How to enable mod_rewrite for Apache 2?

In order to enable mod_rewrite on your server, you can type the following command in the terminal:

Enable mod_rewrite

sudo a2enmod rewrite

Restart apache2 after

sudo /etc/init.d/apache2 restart


sudo service apache2 restart

or as per new unified System Control Way

sudo systemctl restart apache2

Edit .htaccess File

Then, if you’d like to update .htaccess, you can use the following instructions:

If .htaccess file is placed in DocumentRoot, then it will redirect all traffic to an index.php file in the DocumentRoot unless the file exists.

So, let’s say you have the following directory structure and http/www/ is the DocumentRoot

Any file that exists in httpdocs will be served to the requester using the .htaccess shown above, however, everything else will be redirected to http/www/index.php. Your application files in includes/app will not be accessible.

If none of the above works, then try editing /etc/apache2/sites-enabled/000-default and any other similar file in the directory:

That’s it

Lets me know in the comments below if this solution worked for you.