Please enable JS

Enabling apache mod_rewrite in Linux/Ubuntu

img

Enabling apache mod_rewrite in Linux/Ubuntu

29 Mar 2020/ Yogesh

When working with apache and web applications we seldom need to work with url rewrites to create pretty urls and to create a basic flow of the MVC pattern.

When working in any framework it is essential for the htaccess to rewrite the url.

Thus we shall enable the apache’s mod_rewrite to enable the url rewrite through htaccess file.

You have your apache and php installed.

Then enable the mod_rewrite for the apache by

$ sudo a2enmod rewrite

Now we need to make some changed to the /etc/apache2/sites-enabled/000-default.conf file to allow overwrite of the url.

Then the file add the following or make changes to look like the following

<Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride All
        Order allow,deny
        allow from all
</Directory>

Take care of the indentations.

So your file should not look like the following.

<VirtualHost *:80>
    <Directory /var/www/html>

        . . .

    </Directory>

    . . .
</VirtualHost>

Finally save the file and restart apache

$ sudo service apache2 restart

Now when you run your web application with htaccess then the RewriteEngine On should work.