我有一个简单的重写规则,按预期正常工作:
RewriteRule ^user/(\w+)/?$ user.php?id=$1
我有一个php文件:
<?php echo $_GET['id']; ?>
使用以下URL可以正常工作,并且id传递没问题:
http://localhost/user?id=JoeUser
我知道mod_rewrite正在运行,因为这个url还会将我发送给user.php:
但JoeUser实际上从未传递给$ 1。我以前从未见过这种行为。它是OS X中的一个错误,还是我错过了什么?
答案 0 :(得分:1)
这是OS X中的错误吗?
不,这不是一个错误。这是MultiViews
选项的效果,默认情况下在Apache配置中启用。选项MultiViews
由Apache's content negotiation module
使用,>> mod_rewrite
之前运行,并使Apache服务器匹配文件扩展名。因此/file
可以在网址中,但它会投放/file.php
。
要关闭它,请使用:
Options -MultiViews
RewriteEngine On
RewriteRule ^user/(\w+)/?$ user.php?id=$1 [L,QSA,NC]