想要使用htaccess从网址中删除参数 我的网址看起来像这样
http://localhost/details?id=179&title=abcdefghij
我想像这样(或任何更好的建议)转换它
http://localhost/details/179/abcdefghij
请帮助我如何实现它
答案 0 :(得分:0)
要将/details?id=123&title=foobar
转换为/details/123/foobar
,您可以在root.htaccess
中使用以下规则:
RewriteEngine on
#1 redirect "/details?id=123&title=foobar" to "/details/123/foobar"
RewriteCond %{THE_REQUEST} /details/?\?id=([^&]+)&title=([^\s]+) [NC]
RewriteRule ^ /details/%1/%2? [L,R]
#2 internally rewrite the requested url "/details/123/foobar" to "/details?id=123&title=foobar"
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^details/([^/]+)/([^/]+)/?$ /details?id=$1&title=$2 [L]