How can I enable mod_rewrite in apache on Ubuntu?

How do you enable mod_rewrite with Apache in Ubuntu 10.04?

I tried copying rewrite.load from /etc/apache2/mods-available to etc/apache2/mods-enabled but that didn't work.


Solution 1:

Try this: sudo a2enmod rewrite, and then restart apache.

Solution 2:

Obsidian's answer to use a2enmod is the proper solution. andol's method would work, but could break on upgrade. What a2enmod does is simply create a symbolic link, so the following two are the same, both proper, solution:

  ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/

or

  a2enmod rewrite

However, a2enmod will look for other types of files, some have .conf and possibly others. There's no reason not to learn this command, though it's important to know what is going on in the background.

Copying the file would make any future admin very unpleased with you. :)

Solution 3:

Actually, while being the kind of wrong solution, copying rewrite.load from ./mods-available/ to ./mods-enabled/ should have worked. Did you remember to restart your apache afterwards?

In any case, ./mods-enabled/ should usually contain symlinks to corresponding files in ./mods-available/. This is, as mentioned by Obsidian, easiest handled by the commands a2enmod and a2dismod.

Apart from enabling the module, you will also have to activate the rewriting. Before you can write your RewriteCond:s and RewriteRule:s there has to be a "RewriteEngine On" in that configuration context.