How to enable .htaccess on apache server?

Could you please describe .htaccess and how to enable it on apache server?

.htaccess is a configuration file for the Apache web server. It’s an extremely powerful tool that can be used to modify the Apache configuration without editing the Apache configuration files directly. Let us see how to create this configuration and use it to restrict directory listings and IP addresses, and to handle redirects.


Enable .htaccess file:  

sudo nano /etc/apache2/sites-available/


After the VirtualHost block () add:  

<Directory /var/www/html/><br />     Options Indexes FollowSymLinks<br />     AllowOverride All<br />     Require all granted<br /> </Directory>



Save the file and restart apache server.

sudo service apache2 restart 

Go to below path and create .htaccess file

cd /var/www/html/  


Block Ips: 

order allow,deny

# This will deny the IP
deny from

# This will deny all IP's from through
deny from 192.0.2


Allow Ips: 

order deny,allow

# Denies all IP's
Deny from all

# This will allow the IP
allow from

# This will allow all IP's from through
allow from 192.0.2