How to enable mod_rewrite in Apache2 on Debian or Ubuntu

If you have installed Apache HTTP server via apt-get or aptitude on Debian or Ubuntu systems, it has mod_rewrite module installed, but not enabled by default. After Apache web server installation, you need to enable mod_rewrite explicitly in order to enjoy its benefit.

What is mod_rewrite?

Apache HTTP web server boasts of extensible features which are realized by the notion of pluggable modules. When building Apache web server, you compile a set of modules you think are necessary, and built them into the web server. One such module is called mod_rewrite which is responsible for dynamically "rewriting" website URLs at the server side. For example, when user asks for "", the requested URL is translated by mod_rewrite into "", which is then handled by the web server.

Why use mod_rewrite?

Webmasters generally use mod_rewrite to improve user-friendliness and search engine friendliness of web sites by exposing more memorable and crawlable URLs to the world. Also, it can help hide any sensitive information such as query strings from URL requests, and hence enhance website safety.

How to enable mod_write on Apache2

The default installation of Apache2 comes with mod_rewrite installed. To check whether this is the case, verify the existence of /etc/apache2/mods-available/rewrite.load.

$ cat /etc/apache2/mods-available/rewrite.load
LoadModule rewrite_module /usr/lib/apache2/modules/

To enable and load mod_rewrite, do the rest of steps.

$ sudo a2enmod rewrite

The above command will create a symbolic link in /etc/apache2/mods-enabled.

$ ls -al /etc/apache2/mods-enabled/rewrite.load
lrwxrwxrwx 1 root root 30 Dec  9 23:10   /etc/apache2/mods-enabled/rewrite.load -> ../mods-available/rewrite.load

Then open up the following file, and replace every occurrence of "AllowOverride None" with "AllowOverride all".

$ sudo vi /etc/apache2/sites-available/default

Finally, restart Apache2.

$ sudo service apache2 restart

Subscribe to Xmodulo

Do you want to receive Linux FAQs, detailed tutorials and tips published at Xmodulo? Enter your email address below, and we will deliver our Linux posts straight to your email box, for free. Delivery powered by Google Feedburner.

Support Xmodulo

Did you find this tutorial helpful? Then please be generous and support Xmodulo!

The following two tabs change content below.
Dan Nanni is the founder and also a regular contributor of He is a Linux/FOSS enthusiast who loves to get his hands dirty with his Linux box. He likes to procrastinate when he is supposed to be busy and productive. When he is otherwise free, he likes to watch movies and shop for the coolest gadgets.

15 thoughts on “How to enable mod_rewrite in Apache2 on Debian or Ubuntu

  1. I am getting an error on Ubuntu 12.04 (EC2)

    * Restarting web server apache2 /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
    /usr/sbin/apache2ctl: 87: ulimit: error setting limit (Operation not permitted)
    (13)Permission denied: make_sock: could not bind to address
    no listening sockets available, shutting down
    Unable to open logs
    Action 'start' failed.
    The Apache error log may have more information.

  2. I'm running ubuntu 13.10 here. I tried to look for the file /etc/apache2/sites-available/defulat
    There is no such file here. Insetead the folder contains two file called 000-default.conf and default-ssl.conf

    If I change 000-default.conf it when I restart apache it shows error that AllowOverride is not allowed in 000-default.conf file.

    • On some installations you will find that the file default does not exist in sites-available.

      The solution is to edit the file /etc/apache2/apache2.conf instead in the way that Dan Nanni mentions.

  3. Dnetclient gave me the answer !

    The changes had to be done in

    All occurrences of "AllowOverride" were changed from "none" to "all"

    Debian 8 (Jessie) with Apache2

    Thank you Dnetclient, thank you so much !!!

Leave a comment

Your email address will not be published. Required fields are marked *