2013-12-19 32 views
1

我的.htaccess文件中有这样一行:的.htaccess重写规则 - 在本地主机上不同的行为和的1and1

RewriteRule ^profile/(.*)$ profile.php?username=$1 [L] 

当我去http://localhost/blah/profile/name(我使用的XAMPP),在profile.php我可以说:

$user_name = $_GET['username'] 

这工作正常。但是当我将它部署到我的1and1服务器并转到http://blah.com/profile/name时,未设置$_GET['username']。为什么它的行为不同?

+0

是否在1and1网络服务器上启用了mod_rewrite? – Zarathuztra

+0

我在phpinfo()中看不到mod_rewrite。它应该在那里吗? – WhiteAlligator

回答

0

尝试关闭Multiviews

Options -Multiviews 

随着多视图打开,mod_negotiation模块将尝试匹配请求现有的文件(连同其路径信息一起)。因此,该模块将看到/profile/something,然后看到有一个/profile.php,并简单地将请求发送到/profile.php,完全绕过mod_rewrite和您的规则。

+0

当我这样做时,我得到一个404错误。 – WhiteAlligator

+0

@WhiteAlligator确保mod_rewrite已打开(可能涉及到1&1支持) –

+0

@WhiteAlligator这就是我上面提到的。有时托管公司会关闭它,或者默认情况下不启用它。如果您自己编译了Web服务器,则可能需要使用该程序包重新编译。 – Zarathuztra