I have the following rewrite rule:

RewriteEngine on
RewriteRule ^([^/]+)/?$ parser.php?id=$1 [QSA,L]

The issue is that when I try to access my homepage by www.site.com, it rewrites it as well to parser.php, why is this and how do I prevent this?

link|improve this question

71% accept rate
It rewrites everything because you're telling it to rewrite everything. Can you share, specifically, what you want to rewrite, and what you don't? – Shane Madden Oct 21 '11 at 16:06
I don't want it to rewrite when I visit the homepage, say www.mysite.com.. everything else is fine to be rewritten – EquinoX Oct 21 '11 at 16:57
feedback

1 Answer

up vote 0 down vote accepted

Exempt the root from the rewrite:

RewriteEngine on
# Allow the rewrite to proceed only if the URI does *not* match this pattern
# The pattern used is ^/$ - this will only match the exact string "/" for the root.
RewriteCond %{REQUEST_URI} !^/$
# Your existing rule
RewriteRule ^([^/]+)/?$ parser.php?id=$1 [QSA,L]
link|improve this answer
I tried this and it still redirects my www.mysite.com to the parser.php – EquinoX Oct 21 '11 at 17:43
Huh. Set a RewriteLog and set RewriteLogLevel 9 and get the output when incorrectly redirects? – Shane Madden Oct 21 '11 at 18:27
Where do I put this RewriteLog, sorry I never used it before – EquinoX Oct 21 '11 at 19:19
In the <VirtualHost> block for your site. – Shane Madden Oct 21 '11 at 19:22
here is the log pastie.org/2737100, it's a huge file – EquinoX Oct 21 '11 at 19:45
show 2 more comments
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.