RewriteRule在服务器端和localhost之间返回不同的结果

时间:2017-08-22 18:23:00

标签: apache .htaccess mod-rewrite wamp

我做错了什么?为什么以下打开文件test.php 这是在我的主目录服务器端正确但不在我的本地主机上?

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

结果在服务器端显示以下页面:example.com/contact 在localhost上,这是打开一种Wamp服务器树,因为我使用Wamp。其他重定向也很有效,例如

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

有人知道造成这种情况的原因吗?

1 个答案:

答案 0 :(得分:1)

将您的规则更改为:

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

并重新测试。

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

模式上的

/?$使请求URI中的尾随斜杠可选。