mod_rewrite& .htaccess无法在OS X Yosemite中传递变量

时间:2016-05-05 16:49:31

标签: php apache .htaccess mod-rewrite osx-yosemite

我有一个简单的重写规则,按预期正常工作:

RewriteRule ^user/(\w+)/?$  user.php?id=$1

我有一个php文件:

<?php echo $_GET['id']; ?>

使用以下URL可以正常工作,并且id传递没问题:

http://localhost/user?id=JoeUser

我知道mod_rewrite正在运行,因为这个url还会将我发送给user.php:

http://localhost/user/JoeUser

但JoeUser实际上从未传递给$ 1。我以前从未见过这种行为。它是OS X中的一个错误,还是我错过了什么?

1 个答案:

答案 0 :(得分:1)

  

这是OS X中的错误吗?

不,这不是一个错误。这是MultiViews选项的效果,默认情况下在Apache配置中启用。选项MultiViewsApache's content negotiation module使用,> mod_rewrite之前运行,并使Apache服务器匹配文件扩展名。因此/file可以在网址中,但它会投放/file.php

要关闭它,请使用:

Options -MultiViews
RewriteEngine On

RewriteRule ^user/(\w+)/?$ user.php?id=$1 [L,QSA,NC]