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/test.com.conf

 

After the VirtualHost block () add:  

<Directory /var/www/html/example.com/public_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/test.com/public_html  

 

Block Ips: 

order allow,deny

# This will deny the IP 192.0.2.9
deny from 192.0.2.9

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

 

Allow Ips: 

order deny,allow

# Denies all IP's
Deny from all

# This will allow the IP 192.0.2.9
allow from 192.0.2.9

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