问题描述
原始网址 - example.com/art.PHP?a=lorem
想要显示为 - example.com/art/lorem
litespeed
服务器 - htaccess 已启用
RewriteEngine ON
RewriteRule ^art/(.*)$ /art.PHP?a=$1 [L]
不起作用
网址仍然是 - example.com/art.PHP?a=lorem
请帮忙
解决方法
您只有重写 example.com/art/lorem
的重写规则,但缺少将 example.com/art.php?a=lorem
重定向到 example.com/art/lorem
的重定向规则。
您可以使用:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+art\.php\?a=([^\s&]+) [NC]
RewriteRule ^ /art/%1? [R=301,L]
RewriteRule ^art/([\w-]+)/?$ art.php?a=$1 [L,QSA]
THE_REQUEST
变量表示 Apache 从您的浏览器收到的原始请求,并且在执行其他重写指令后不会被覆盖。此变量的示例值为 GET /index.php?id=123 HTTP/1.1
参考: