Apache/PHP 确定提供错误的文件 [英] Apache/PHP is determined to serve the wrong file
问题描述
我有一个页面,它的网址是这样的http://testserver/path/to/foo/bar/
但 apache 服务的文件完全错误.
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/
是所有代码和 .htaccess
文件所在的真实目录.foo/bar/
应该使用 RewriteRule
重定向到 foo_bar.php
,但它永远不会到达那里.这不是 mod_rewrite
问题,因为我已经注释掉了所有可能会产生干扰的规则,这应该给我 404 请求,但会出现同样的问题:
/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:
提供的文件是/path/to/foo.php
,所以在其中我 var_dump
$_SERVER
并得到: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/
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?
推荐答案
你有 mod_negotiation
安装了吗?如果是这样,那将接受您的请求并尝试找出您真正想要的文件.不幸的是,mod_negotiation
被 mod_rewrite
的 reroute-magic 弄糊涂了,所以当你尝试重写请求时一定要禁用 mod_negotiation
的 MultiViews 选项.
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.
如果您的覆盖设置允许,您可以使用 Options -MultiViews
在您的 .htaccess
文件中禁用多视图.
If your overwrite settings allow it, you can disable MultiViews with: Options -MultiViews
in your .htaccess
file.
这篇关于Apache/PHP 确定提供错误的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!