我有一个像
www.website.com/index.php
这样的网站,它是主页。
我选择具有多个参数的不同产品,例如 www.website.com/index.php?id=xxx
或 www.website.com/index.php?cat=xxxx
我的 htaccess 中有几行用于重定向查询。例如,对于我使用以下代码的产品:
RewriteCond %{THE_REQUEST} \s/+index\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /product/%1? [R=301,L,NE]
RewriteRule ^product/([\w-]+)/?$ index.php?id=$1 [L,QSA,NC]
效果很好。
现在我想将不带任何参数的index.php请求重定向到域根目录,所以
www.website.com/index.php
应该变成www.website.com
。任何其他查询不应受到影响。我该怎么做?
# test that the query string is empty
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^index\.php$ / [R=301]
这应该可以完成任务。