1

所以我在 htaccess 文件中有以下重写:

RewriteRule ^([^/.]+)/?$ index.php?page=$1 [L]

每当我尝试访问时,http://domain/index我都会得到 404,但是当我尝试访问http://domain/index.甚至不存在的页面http://domain/a时,重写工作正常,并且 index.phpvar_dump()是适当的值。

index.php 中唯一的代码是var_dump($_GET);,所以我知道这不是 php 问题。

有人可以向我解释我的重写规则有什么问题,并解释如何解决它吗?

编辑: 我忘了我启用了错误日志记录。它一直保存到 error.log 的错误是:

[Sun Feb 24 21:01:18 2013] [error] [client 192.168.1.1] Negotiation: discovered file(s) matching request: /path/public_html/index (None could be negotiated).
4

2 回答 2

3

由于错误,似乎 MultiViews 已启用。

您可以在文件顶部尝试此操作:

Options +FollowSymlinks -MultiViews

另外,我建议如下:

# Prevent loops
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule ^([^/]+)/? index.php?page=$1 [L] 

MultiViews 提供 Content Negotiation, 最好在这里描述

于 2013-02-25T06:28:30.853 回答
1

MultiViews启用 ( Options +MultiViews) 时,模块Content Negotiation会查找匹配的文件index,但.php文件不符合匹配条件,因此会失败并显示None could be negotiated. 您可以.php使用以下方法将处理程序添加为匹配项:

MultiviewsMatch Handlers Filters

MultiviewsMatch.

于 2014-04-28T16:46:56.013 回答