mod_rewrite in .htaccess - inconsistency between local and server environment

Giganews Newsgroups
Subject: mod_rewrite in .htaccess - inconsistency between local and server environment
Posted by:  Thomas Mlynarczyk (thom…@mlynarczyk-webdesign.de)
Date: Thu, 10 Jul 2008

Hello,

I want to rewrite

www.example.com/foo/bar
into
www.example.com/foo/index.php?page=bar
where both index.php and .htaccess are in the /foo directory. I thought
the following would do it:

/foo/.htaccess:
RewriteEngine On
# Leave these special files and all subdirs untouched
RewriteRule ^(index.php|favicon.ico|robots.txt|[A-Za-z0-9-]+/) - [QSA,L]
# Do the trick
RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]

But it turns out I must write

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

to make it work. I thought the rewrite engine always works from the
current directory and thus should not see /foo/. Moreover, I cannot call
www.example.com/foo - I *must* put a slash at the end to make it work.
In my local environment, however, the code works without the
modification. How must I rewrite this so it will work from root or any
subdirectory, and not require the trailing slash? (It's a website under
development, thus currently in the foo directory, but one it's finished
it will be moved to the root.)

Greetings,
Thomas

--
Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!
(Coluche)

Replies