>我有以下网址:
www.example.com/profile?id=31
我想将其重定向到:
www.example.com/profile/id/31
我该怎么做??
我尝试使用这个:
RewriteCond %{QUERY_STRING} (^|&)id=31($|&)
RewriteRule ^www.example.com/profile$ /www.example.com/profile/id/31?&%{QUERY_STRING}
但它不起作用
尝试下面,
RewriteCond %{QUERY_STRING} ^(.+)=(.+)
RewriteRule ^(.+)$ http://www.example.com/$1/$2/$3 [R=301,L,QSD]
我正在使用匹配组,因此它适用于给定相似模式的任何值。
我会选择这样的事情,让我知道它是否有帮助:
RewriteRule ^ profile/([0-9]+)/?$ /profile?id=$1 [NC,L,QSA]
它的作用在这篇文章的 https://stackoverflow.com/a/20566547/6517383 和其他答案中得到了广泛的解释。