Search code examples
mod-rewriteurl-rewritingmode

Url Rewrite => Internal Server Error


I am getting internal server errors every time i implement this code for mod-rewriting in my .htaccess file:

RewriteEngine On 
RewriteRule ^([^/]*)\.php$ /index.php?site=$1 [L]

I am trying to convert:

www.mydomain.com/index.php?site=mysite

to

www.mydomain.com/mysite.php

The error:

Internal Server Error

Any help would be greatly appreciated, Thanks


Solution

  • Your rule is causing an infinite loop because it's rewriting all requests ending in .php. This includes index.php too and so it ends up rewriting it to index.php again and again and so on..

    Just add a condition to your rule that excludes it.

    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} !^/index\.php [NC]
    RewriteRule ^([^/]*)\.php$ /index.php?site=$1 [L]