htaccess rewriterule leading slash

Posted by Tiddo on Server Fault See other posts from Server Fault or by Tiddo
Published on 2012-03-25T21:25:44Z Indexed on 2012/03/25 23:31 UTC
Read the original article Hit count: 190

Filed under:
|

I'm using htaccess to rewrite my urls so that I can have nice clean urls. However, the same htaccess file does different things on my local server and my remote server:

On my local server the url to the website is like http://localhost/example/ and on my remote server the url is http://example.com/.

For my local server I can use the following htaccess redirect rule:

RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

However, when I use this on my remote server I get an internal server error. Instead I have to use this: (note the leading slash)

RewriteRule ^(.*)$ /index.php?page=$1 [L,QSA]

Unfortunately this doesn't work on my local server: this rewrite rule requests http://localhost/index.php instead of http://localhost/example/index.php on my local server.

How can I make this work on both my remote and local server?

© Server Fault or respective owner

Related posts about .htaccess

Related posts about mod-rewrite