views:

87

answers:

3

I have a page that is called with a url like http://testserver/path/to/foo/bar/ but apache is serving the wrong file altogether.

/path/to/ is a real directory where all the code and .htaccess file is. foo/bar/ is supposed to redirect to foo_bar.php with a RewriteRule, but it never gets there. It's not a mod_rewrite issue as I have commented out all the rules that could be interfering, which should give me 404s for that request, but the same problem occurs:

the file that is served is /path/to/foo.php, so in it I var_dump $_SERVER and get:
REQUEST_URI = /path/to/foo/bar/
SCRIPT_NAME = /path/to/foo.php
SCRIPT_FILENAME = /real/path/to/foo.php
PATH_INFO = /bar/
PATH_TRANSLATED = /real/bar/
PHP_SELF = /path/to/foo.php/bar/

Why is this request being routed to this file at all?

A: 

Do you have mod_negotiation installed? If so, that'll take your request and try to work out what file you really meant. Unfortunately mod_negotiation gets confused by the reroute-magic from mod_rewrite, so make sure you disable mod_negotiation's MultiViews option when you try to rewrite the request.

If your overwrite settings allow it, you can disable MultiViews with: Options -MultiViews in your .htaccess file.

Jacco
thanks. what an awful module to have on by default. i can't believe it does its thing before mod_rewrite.
Lucas
A: 

mod_speling could be the culprit. If it is enabled on your server. Try to disable it. http://httpd.apache.org/docs/1.3/mod/mod_speling.html

murze
A: 

It's one of the modules mentioned in @murze's and @Jacco's answers in combination with the PATH_INFO mechanism that is used to "simulate" mod_rewrite-style URL rewriting.

Using pathinfo, you can do the following:

http://testserver/index.php/path/to/foo/bar/1/2/3/

This will invoke index.php and serve the remaining URL fragment as PATH_INFO. This is used, as I said, to set up a central front controller with "beautiful" URLs without mod_rewrite.

Now in your case, the same thing happens, only that

http://testserver/path/to/foo

gets translated - either through mod_speling, the negotiation module or a third module whose name I forgot - into

http://testserver/path/to/foo.php

The rest of the path gets faithfully passed to that file.

So it's intended behaviour, albeit weird and unexpected.

Pekka