Apache/PHP is determined to serve the wrong file

為{幸葍}努か 提交于 2019-12-13 01:54:10

问题


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?


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/2620635/apache-php-is-determined-to-serve-the-wrong-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!