mod_rewrite Not Working in .htaccess - Solution

By Angsuman Chakraborty, Gaea News Network
Monday, July 10, 2006

I faced a hair-tearing problem. mod_rewrite was loaded and yet it was not working in .htaccess files (and httpd.conf initially). Here is the solution along with how you can debug mod_rewrite problems.

Debugging procedure:
Add these two line to your httpd.conf immediately after RewriteEngine On.
RewriteLog “/var/log/httpd/rewrite_log”
RewriteLogLevel 9

After that I added the required RewriteRule etc.

The reason for testing directly in httpd.conf is to ensure that mod_rewrite is working in the first place. After some debugging I realized my expression was wrong. So now I found mod_rewrite was working in httpd.conf. However it still wasn’t working in .htaccess files.

Solution:
I found AllowOverride was set to None in httpd.conf. I changed it to All (after all I am the only user of the machine). And it finally started working everywhere (after a restart).

What I learnt:
Unmanaged dedicated web hosting is really really painful, unless you are (or have) a good linux system administrator. Too many things to setup and too many points of failure. And I haven’t even started working on serious hardening stuff.

Discussion

JohnM
January 4, 2010: 6:38 pm

Thank you… thank you… thank you. I was just about to quit web development and take religious vows. RewriteLogLevel 9 - Awesome

December 2, 2009: 5:07 pm

was going insane and your quick tip of “I found AllowOverride was set to None in httpd.conf” was the key! years on your still helping folk!

thanks


Sajith
November 27, 2009: 2:23 am

Thanks dude! it was helpful.


Paul
November 6, 2009: 6:59 pm

Thanks. The RewriteLog tip is a good one.

October 14, 2009: 5:33 am

thanks for this - saved my sanity!

September 30, 2009: 4:07 am

Haha, like everybody else, thanks! Perfect solution.


MJ
August 24, 2009: 1:58 pm

Thanks for this info. It really helped.


Travis
July 16, 2009: 1:52 am

Thanks a lot for this.

Helped me get mod_rewrite going on a new OS X Leopard install, with a slightly different log path: “/var/log/apache2/rewrite_log”.

May 17, 2009: 6:16 pm

It’s working! Tnx!


Jeff
March 1, 2009: 3:31 am

this help me out of a problem that I was having.. THANKS!


omg
February 2, 2009: 4:02 am

just a thanks- i was getting sick trying to find this solution!

June 6, 2008: 1:44 am

Thanks. You save my life!


Luca
April 18, 2008: 10:28 am

this one was it :) banging my head on it for hours, thanks to you and google


rajv
March 23, 2008: 2:29 pm

Thanks a lot, this fixed my problem as well.


Jcart
December 23, 2007: 11:40 am

Thanks Angsuman! It worked wonders :)


Saurabh
December 22, 2007: 11:01 pm

I dont get any error in rewrite_log nor rewite is working.

December 20, 2007: 9:55 pm

Man, when you said hair pulling, you weren’t kidding. I probably spent 4-5 hours trying to resolve the same issue. This game is not for people with short attention spans.

October 19, 2007: 12:50 pm

Thank you so much, I’ve been trying everything and the AllowOverride has worked.

March 10, 2007: 3:01 pm

THANKS A LOT!!! Your so small, but so clever tip saved my permalinks from death :)


SacrificE
August 15, 2006: 7:23 am

Thanks DOOD ! =)))) it worked for me !
thx a lot!


Matt
July 15, 2006: 6:52 pm

Thanks! I was racking my brain trying to figure it out…AllowOverride was set to None in httpd.conf

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :