RewriteRule 在服务器端和本地主机之间返回不同的结果

RewriteRule returning a different result between server side and localhost

我做错了什么?为什么下面会打开文件test.php 哪个在服务器端正确地位于我的主目录中,但不在我的本地主机上?

RewriteEngine On
RewriteRule ^(contact)$ /test\.php?view= [QSA,L]

作为服务器端的结果,我显示了以下页面:example.com/contact 在本地主机上,这是打开一种 Wamp 服务器树,因为我使用的是 Wamp。其他重定向运行良好,例如

RewriteRule ^index\.html$ /index\.php [QSA,L]

有人知道是什么导致了这种情况吗?

将您的规则更改为:

 RewriteRule ^(contact)/?$ test.php?view= [QSA,L,NC]

并重新测试。

这将在保存 .htaccess 的同一目录中将 contact 重写为 test.php。由于目标 URI 中的前导 /,您的规则将相同的请求重写到站点根目录中的 test.php

/?$ 模式使请求 URI 中的尾部斜线可选。