.htaccess htaccess-隐藏文件扩展名并仅保留变量的值

.htaccess htaccess-隐藏文件扩展名并仅保留变量的值,.htaccess,url-rewriting,litespeed,.htaccess,Url Rewriting,Litespeed,原始url-example.com/art.php?a=lorem 希望显示为-example.com/art/lorem litespeedserver-htaccess已启用 RewriteEngine ON RewriteRule ^art/(.*)$ /art.php?a=$1 [L] 不起作用 url仍然是-example.com/art.php?a=lorem 请帮助您只需要重写example.com/art/lorem,但缺少重定向example.com/art.php?a=lo

原始url-
example.com/art.php?a=lorem

希望显示为-
example.com/art/lorem

litespeed
server-htaccess已启用

RewriteEngine ON
RewriteRule ^art/(.*)$ /art.php?a=$1 [L]
不起作用
url仍然是-
example.com/art.php?a=lorem


请帮助

您只需要重写
example.com/art/lorem
,但缺少重定向
example.com/art.php?a=lorem
example.com/art/lorem
的重定向规则

您可以使用:

重新编写引擎打开
RewriteCond%{THE_REQUEST}\s/+art\.php\?a=([^\s&]+)[NC]
是否重写规则^/art/%1?[R=301,L]
重写规则^art/([\w-]+)/?$art.php?a=$1[L,QSA]
_REQUEST
变量表示Apache从浏览器收到的原始请求,在执行其他重写指令后不会被覆盖。此变量的示例值为
GET/index.php?id=123 HTTP/1.1

参考文献:


很有效,非常感谢,特别是您的解释。我对
.htaccess
的所有内容都感到困惑,无法为初学者找到任何参考资料。顺便说一句,看到这一行,但类似的解决方案-
https://css-tricks.com/snippets/htaccess/remove-file-extention-from-urls/
我在回答中添加了大量参考链接。