How to use .htaccess file in apache2 Ubuntu

The .htaccess file can be used in apache server to have it’s own configuration per directory.

1: First step is to enable mod_rewrite module

sudo a2enmod rewrite

2: Now restart the apache server

sudo service apache2 restart

3: Open the default VirtualHost file with any editor you like.

sudo nano /etc/apache2/sites-available/000-default.conf

4: Look for DocumentRoot in the VirtualHost and place this code just below it.

<Directory "/var/www/html">
    AllowOverride All
</Directory>

5: Exit and save the changes in nano editor by entering ‘CTRL-X’ then ‘Y’ and hit Enter.

6: Now again restart the apache server

sudo service apache2 restart

7: place your .htaccess file in your desired root directory which in this is is /var/www/html

Done!!

Leave a Reply

Your email address will not be published.