The following only applies to the Apache which ships with Ubuntu — so if you’re wondering why your mod_rewrite isn’t working with something else, chances are this won’t be that helpful.
I was playing with mod_rewrite in the context of WordPress 1.5 for use as a CMS on a new website, and it basically wasn’t working at all. The module was there, it was enabled, but it was doing absolutely nothing. I reinstalled Apache manually (from source), and tried to do the painful stuff that goes with that (PHP ./configure options, anyone? Some people might be able to do it, but not me!), but gave up in disdain when I realised I had 2 hours to get work done before a meeting and didn’t have a working Apache install to get it working on. mod_rewrite or not, it was back to the stock install that “sort of” worked.
mod_rewrite wasn’t working for the meeting, but that didn’t really matter… I’ve discovered that I care more about friendly URLs than most other people I’ve ever met in real life! That evening, I looked at the problem again, and, after trawling through apache2.conf (Ubuntu’s equivalent of httpd.conf — don’t ask why, I don’t think even they know) and talking to Michael about it, I discovered that I’d been looking in the wrong place.
It doesn’t matter whether rewrite.conf is in the mods-enabled folder (although it needs to be — but that’s not the issue at hand here) — by default, Ubuntu’s Apache install has a default virtual host setup under “sites-enabled” (actually just a symlink to “sites_available” — this is best practice when creating new vhosts, by the way: stick the config in sites-available and symlink to that from sites-enabled… there are a few reasons for this, which wouldn’t really affect the casual user, but if you were running LOTS of websites off it it’d soon become helpful if you needed to disable websites because of policy violations or billing without actually deleting the configuration.), instead of just the single “real” server. Okay, this probably makes sense… but for the fact that it didn’t SAY it anywhere, and additionally, despite having support for .htaccess files built into the apache2.conf file, it’s set to do absolutely nothing in the virtual host config “default”.
Basically, to get mod_rewrite to work, load the module by symlinking to mods-available/rewrite.conf in mods-enabled, then set AllowOverride to “all” in sites-available/default in both the root (“/”) container and the /var/www/ container. Whilst you’re there, it may be a good idea to get rid of the RedirectMatch, simply because it’s annoying… I haven’t, but only because I haven’t bothered to put something in the root of the default site.
This stuff is probably self explanatory to many, but it took me too long to realise it, even with help, and in my trawlings of Google I hadn’t found anything to say how to do it, so there we are.

Good information *will remember if I try ubuntu*.
I had the same problem (sort of) on my mac. It was a pain because of the crazy root access, or lack of.
Thanks for your hint, I found this on Google and it helped my gallery installation on Ubuntu a lot.
I have one little remark, it’s not mods_enabled and mods_available but mods-enabled and mods-available (dash instead of underscore), subtle difference, but it makes all the difference when trying to locate these dirs if you don’t know where they are.
Other than that, thanks, it worked perfectly!
Oh, of course! Sorry about that, post edited.
[…] buntu server, but I finally got it right. Here’s a quick and easy guide for doing it here. Before following the guide, make sure you have apache-util […]
sudo a2enmod rewrite
will do it for you. ;) But thanks for the pointer.
Thanks alot for the tip, worked great.
This may be a Debian thing.
I used this tip on a Mepis install and both Ubuntu and Mepis
are based on Debian
cannot thank you enough! i had the same problem with wordpress and your one trick of “set AllowOverride to “all”” did it!
thanks again!
–prash.
Thanks, this help me fix gallery. Regards –GyY
Thanks for this. Made my pointless change from Gentoo to Ubuntu easier. Why on Earth isn’t this enabled by default? Guess it’s a Debian security paranoia issue.
Another person you helped with Gallery ^^;
This post is very helpful but might be much for configuring Apache mod_rewrite with wordpress which need per-directory configuration(.htaccess).
If you are like me and configure mod_rewrite from Apache Server side(i.e. the Ubuntu default Apache2 Server) instead of .htaccess, you might not need to change AllowOverride directive. the following steps worked for me.
1) % sudo a2enmod rewrite
2) % sudo /etc/init.d/apache2 force-reload
3) % sudo vi /etc/apache2/sites-enabled/000-default
.….….….…..
RewriteEngine on
RewriteRule **************
.….….….…..
4) % apache2ctl graceful
You may need to put your RewriteRule within container of your sites-configuration file instead of in the file “/etc/apache2/mods-enabled/rewrite.conf”.
hope this help..
Xicheng
Just as a note — in 6.0.6 the entry for mod_rewrite in the mods-available directory has been changed to rewrite.load.
Great article, it’s very useful!
Ah! Thanks for this. Was stuck on the first step of trying out the Zend framework working; till google gave me this link. You just saved me hours of wasted time. Cheers…
I’ve been thinking about switching from Mandriva to kubuntu for a while and ran into problems with mod_rewrite not working. I spent probably 2-3hrs last night trying stuff and reading various things I found on google. At first I thought my .htaccess was messed up until I made the rewrite commands as simple as possible and it still didn’t work.
Did another search today and found this page which pointed me right to the problem in the sites-available/default folder. Thanks :)
Thanks, this was exactly what I was looking for. Now my wordpress permalinks work!
Another thank you. Scratching my head why a local apache2 install on my laptop wasn’t working with mod_rewrite. Google found your easy answer.
Another person you helped — this one with drupal! Thanks loads for this clear, concise and useful post!
This tip helped me as well playing with drupal. Thanks for the post :-)
Wow. Found this on Google and it was exactly what I was looking for. I thought I had to recompile Apache 2.0 (which I have zero idea how to do; I cannot live without apt-get!), but after reading this I looked in my modes-available directory and there it was!! Duh! I should have looked there. Thanks!
Great Article!
This makes mod_rewrite and ME happy!
Thx a bunch
Thanks man, that worked great! I’m installing CakePHP on Ubuntu and the test page wasn’t loading the CSS or images properly. But after I set AllowOverride to ‘all’ in the / and /var/www/ directories in the /etc/apache2/sites-available/default file and created a symlink (or ln –sf ) it worked great. The only difference is that my symlink file was rewrite.load, not conf. Not sure why, but it works now, thanks!
I do everything I found on Google to enable mod_rewrite, (including sudo a2enmod rewrite ), but it just didn’t work. Then I found this. A million thanks my friend!
Another soul saved here. Cheers.
Thanks!
Thanks a lot! You have no idea how long I’ve been trying to sort mod_rewrite out! Took me ages to find this article.
Thanks, very helpfull !
just open /etc/apache2/sites-available/000-default and set AllowOverride to All
then restart apache using /etec/init.d/apache2 force-reload
excellent tutorial
I still can’t get it to work. I have tried every combination of the various changes described in this article and its comments that I could think of. Using Ubuntu 6.06.1. All my RewriteRules are defined in httpd.conf, which is included via apache2.conf. I set RewriteEngine On, and also added RewriteLog and RerwriteLogLevel statements for debugging. The log file I specified was created the next time I restarted apache, but nothing ever gets written to it (it is 0 bytes in size). Anybody have any thoughts?
Update: I got it to work by putting the RewriteRule statements in /etc/apache2/sites-available/default. Not sure why they didn’t work from httpd.conf.
Additional update: in place of the RewriteRule statements in /etc/apache2/sites-available/default, I put an Include statement for httpd.conf, and that worked. I removed the Include of httpd.conf from apache2.conf. I think it has something to do with the RewriteRule statements being called from within the context of the VirtualHost.
How if the document is out of /var/www/ ? Cause I am too lazy if scripting via terminal and sudo. Many thanks to you. I’m sorry aboute my english.
Yes, thanks so much. I have been reading a book Search Enging Optimizations with PHP and it has good pointers and tests for mod_rewrite, but it didn’t mention setting the AllowOverride to all. That did the trick! Thanks for posting this.
THanks so much for this! You don’t know how long I’ve been trying to fix it. I guess I just assumed rewrites would be allowed by default vhost!
Joshua, you’re a genius. :) I’d been fighting it for a long time, and had given up. I guess I used different search terms, because your site was #3 for the ones I used this time, and your change (AllowOverride all instead of None) is what made it work.
Thanks!
Absolutely brilliantly right on the dot for what I needed on my desktop development box I use for work!
You sir, are the man.
you could also just put the contents of your .htaccess file in the site conf file in a
and change the override at that level rather then the server root.
thanks… iwould have spent hours on that without u ;-) !!!
THANKS A LOT!, after 3 hours researching this problem in m y ubuntu box, i found you… thanks dude!
Thanks man, I just bought a new machine and was enjoying it, ’till I got stuck with mod_rewrite. Works like a charm now, take care :)
Thanks a lot…
Thanx for the tip, I’ve been searching of why mod-rewrite would spit out 404 errors on my Joomla installation, seems “sudo a2enmod rewrite” is not the onlything I need to do.
I did figure it had to do with “AllowOverrides” though. Thanx a lot.
Good one man!
This helped me with my CakePHP installation.
It had me wondering for a while… I was lucky to come across this site pretty early on!
Keep up the good work!
Thanks mate, this helped (at last).
Guys, why not adopt XiCheng’s method at floor 12,
need not fucking AllowOverrides.
sudo ln –s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load
vi /etc/apache2/sites-enabled/000-default
NameVirtualHost *
…
RewriteEngine on
RewriteRule ^/(.+)\.(exe|zip|rar)$ /!index/download.php?file=/$1.$2
sudo /etc/init.d/apache2 restart
vi /etc/apache2/sites-enabled/000-default
NameVirtualHost *
<VirtualHost *>
…
RewriteEngine on
RewriteRule ^/(.+)\.(exe|zip|rar)$ /!index/download.php?file=/$1.$2
</VirtualHost>
unfortunately, it doesn’t work for me…and I really don’t know what am I doing wrong. All is set as it is described here, mod_rewrite works nice on my website, but not at localhost. Any ideas?
found a mistake, sorry … a stupid mistake with the default config file (I had 2!!!! with different settings)…
thanks a lot for tip :)
Thanks SO MUCH! This finally fixed a WordPress-MU problem I was having. I didn’t know you had to Allow at the base level for Alias Allow’s to work as well. Happy Happy Joy Joy!
Hi
I have the same problem about mod_rewrite
I want install SilverStripe on LocalHost XAMPP
I’m not a programmer and i dont underestand your description
Tell me easily please
Another grateful reader — I had problems making clean urls with pmwiki, and couldn’t figure out why my setup on my own Ubuntu box was any different from the one on red hat at work.
Thanks.
I was as giddy as a little school girl. I literally stood up cheered and laughing. Even shed a tear of joy after getting this to work. Anyone working for Ubuntu here’s your sign. WAAAHOOOOOOOOOOOOOO!
Thanks fot publishing this tip, i was struggling making cakephp work. This solved my problem.
for cakephp
http://komunitasweb.com/2009/02/cakephp-tutorial-installing-cakephp-on-ubuntu/
Tnx for this!
It also worked for me. Been trying to get an Elgg install up for some hours:)
Had missed AllowOverride All in /var/www Directory
thanks, this saved a bunch of hours.
Your the man! Thanks so much.
[…] pas « standard » sur Ubuntu. J’ai donc suivi les recommandations du blog de Josh Street pour corriger le […]
[…] Basically, to get mod_rewrite to work, load the module by linking to mods-available/rewrite.conf in mods-enabled, then set AllowOver ride to “all” in sites-available/default in both the root (“/”) container and the /var/www/ container (Copy & paste from here). […]
thanks man, i’ve seen a lot of solution but this is the real one. thanks again.
THanks man, you are life saver, “AllOverride all” did the job after enabling mod_rewrite
Thank you, very match )
Hi, Thanks a lot. really useful. This solved my problem.
Oh my god this should be in the manual of LAMP for Ubuntu :)
Works like a charm! Thanks
Six and a half years on, this page is still a very handy resource. Thanks.
I can’t make this s*** work!
I know is because “Basically, to get mod_rewrite to work, load the module by symlinking to mods-available/rewrite.conf in mods-enabled”.
But i can’t find the file ‘rewrite.conf’ so i can’t make the bloody link…
I will never understand why the author didn’t provide some terminal command… i guess he likes poetry and talks.
Useless article for me and a big waste of time. I’m started to get sickened by Ubuntu: in the last 2 days 0 work @ my projects but full time work in making mysql, phpmyadmin, wordpress, netbeans and everything work on Ubuntu. I hope this pays off… i really really do!
I was so frustrated when i wrote the above. It worked after i figured this: http://ubuntuforums.org/showthread.php?p=11326472
So this article is still good even after 6 years… amazing!
Why is this the default without saying it anywhere?! Thanks so much, I’ve been struggling for days trying to get mod_rewrite to work with my Elgg install but no luck. After reading your article everything is solved in a jiffie, I can’t thank you enough!