Oct 21, 2011
tom

.htaccess rewrite issues with homepage

Question

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?

Answer

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]

Related posts:

  1. htaccess mod rewrite problem
  2. Using IIS URL Rewrite to redirect from the homepage
  3. How do I use .htaccess conditional redirects for multiple domains?
  4. URL rewrite with multiple parameters using .htaccess
  5. rewrite rule for .htaccess not working for php file

Leave a comment