Apache 将index.php和任何查询字符串重定向到根文件夹
我有一个简单的Htaces将index.php重定向到根文件夹:Apache 将index.php和任何查询字符串重定向到根文件夹,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有一个简单的Htaces将index.php重定向到根文件夹: RewriteEngine On RewriteCond %{THE_REQUEST} ^.*/index\.php RewriteRule ^(.*)index.php$ /$1 [R=301,L] 我发现它仍然将查询字符串附加到index.php。例如: http://domain.com/index.php?query=string 将被重定向到: http://domain.com/?query=string 如何
RewriteEngine On
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]
我发现它仍然将查询字符串附加到index.php。例如:
http://domain.com/index.php?query=string
将被重定向到:
http://domain.com/?query=string
如何删除任何查询字符串?重定向时添加标志:
RewriteRule ^(.*)index.php$ /$1 [QSD,R=301,L]
不过,正如Apache文档中提到的那样
此标志在2.4.0及更高版本中可用
对于较旧的Apache版本,您可以通过传递自己的查询字符串来丢弃它们:
RewriteRule ^(.*)index.php$ /$1? [R=301,L]
注意重定向中孤独的
?
。我试过了,但没有效果。这意味着我有一个较旧的Apache版本?:“当您想要删除现有的查询字符串时,请在替换字符串的末尾加一个问号。”