htaccess - 删除index.php,但当index.php?z=abc 时不删除index.php
http://domain.com/index.php -> http://domain.com/ - 好的
http://domain.com/index.php?z=abc -> http://domain.com/index.php?z=abc - 不好,保持不变。 使用下面的代码可以实现这一点:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
如何修改此代码以便
http:// domain.com/index.php?z=abc -> http:// domain.com/?z=abc
http:// domain.com/index.php -> http:// domain.com/ - OK
http:// domain.com/index.php?z=abc -> http:// domain.com/index.php?z=abc - not OK, stays the same.
This works using the code below:
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
How to modify this code so that
http:// domain.com/index.php?z=abc -> http:// domain.com/?z=abc
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Apache 将自动处理查询字符串。你所需要的只是这个:
Apache will take care of the query string automatically. All you need is this:
尝试下面修改后的 RewriteCond
Try the modified RewriteCond below