0

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

and anything else I've thrown at it, except if the first parameter is index.

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.

3
  • 1
    try adding Options -MultiViews to your htaccess, to prevent the clash with index.php Commented Mar 15, 2012 at 18:44
  • Brilliant. That's exactly what I needed to do. Thanks! I guess that's some sort of content negotiation. Commented Mar 16, 2012 at 4:11
  • 1
    Yes it is, and Multiviews takes precedence over mod_rewrite, resulting in your problem. Commented Mar 16, 2012 at 13:16

1 Answer 1

1

Try adding Options -MultiViews to your htaccess, to prevent the clash with index.php

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.