Welcome to the Hindi Tutor QA. Create an account or login for asking a question and writing an answer.
Sima in Web Hosting

.htaccess Not Working on ubuntu, I’ve followed the tutorial to setup mod_rewrite. If I type sudo a2enmod rewrite it indicates Module rewrite already enabled. However, the rewrite rules do not work.

1 Answer

0 votes

Rewite module (.htaccess not working)

Found the solution,

First of all login to your server, run these commands:

sudo a2enmod rewrite
sudo systemctl restart apache2

Open /etc/apache2/sites-enabled/000-default.conf file by the below command. If you already installed ssl on your server via Let's Encrypt, run the second line command.

sudo nano /etc/apache2/sites-enabled/000-default.conf
sudo nano /etc/apache2/sites-enabled/000-default-le-ssl.conf

Paste below lines after <VirtualHost *:80> and before </VirtualHost>:

 <Directory /var/www/html>
    AllowOverride All

Now restart apache server:

sudo service apache2 restart

Now I am sure that .htaccess file will work 100%.

Hint: if you can, disable AllowOverride and add rewrite rules to vhost config in directory section you can gain some performace boost because if AllowOverride is on, then Apache2 search in every directory within DocumentRoot for htaccess in every request.

Related questions