I have the following mod_rewrite directives in a .htaccess file, so that URLs like http://example.com/foo/bar/baz are internally rewritten to index.php?page=baz
RewriteEngine on RewriteBase /foo/bar/ RewriteRule ^index.php - [L,NC] RewriteRule ^([^/]*)/?$ index.php?&p=$1 [L,QSA] RewriteRule ^([^/]*)/([^/]*)/?$ index.php?&p=$1&v=$2 [L,QSA] It works fine at
- http://example.com/foo/bar/baz
- http://example.com/foo/bar/page/part
- http://example.com/foo/bar/foobar/baz
and anything else I've thrown at it, except if the first parameter is index.
- http://example.com/foo/bar/index and
- http://example.com/foo/bar/index/baz do not work.
I've turned RewriteLogLevel up to 9, and I get entries like this one when I visit http://example.com/foo/bar/index/baz
[perdir ..../foo/bar/] add path info postfix: ..../foo/bar/index.php -> ..../foo/bar/index.php/baz So it looks like something internal to apache is actually rewriting the /index/ part of the URL to /index.php/ before mod_rewrite even sees it, which is a bit of a problem. It isn't rewriting anything else incorrectly, just index.
I really don't understand why it won't work with index but will with everything else. These are the only rewrite directives for this project, and it's a stock setup otherwise.
This is Apache 2.2.21 and PHP 5.3.8.
I hope I'm being clear, but just in case, I want URLs rewritten like this:
- /foo/bar/index --> /foo/bar/index.php?page=index
- /foo/bar/index/ --> /foo/bar/index.php?page=index
- /foo/bar/page1 --> /foo/bar/index.php?page=page1
- /foo/bar/page2/word --> /foo/bar/index.php?page=page2&v=word
It all works fine, except for URLs with index.
Options -MultiViewsto your htaccess, to prevent the clash withindex.php