apache重定向去掉自动加上的query string

需求:
当网址是

http://xxx.xxx.xxx/a.php?b=c&d=356&e=fsdfsadfsdfdfsdf

跳转到

http://xxx.xxx.xxx/356.html

要取到之前网址中的356这个位置的参数,于是

RewriteEngine on
RewriteCond %{QUERY_STRING} ^b=c(.*)$
RewriteRule (.*) %{QUERY_STRING}
RewriteRule ^b=c&d=(.*)&(.*) http://xxx.xxx.com/$1.html [R=301,L]

但是实际操作之后跳转的网址变成了

http://xxx.xxx.xxx/356.html?b=c&d=356&e=fsdfsadfsdfdfsdf

apache自动加上了之前url里面的querystring参数,搜索了下,发现只要在最后加上一个问号,就ok了
参考http://www.dewen.io/q/5256/Apache+Rewrite%E5%BC%BA%E5%88%B6%E8%BD%AC%E5%8F%91+%E5%8E%BB%E9%99%A4+Query+String%E9%97%AE%E9%A2%98

RewriteEngine on
RewriteCond %{QUERY_STRING} ^b=c(.*)$
RewriteRule (.*) %{QUERY_STRING}
RewriteRule ^b=c&d=(.*)&(.*) http://xxx.xxx.com/$1.html? [R=301,L]

标签: none

添加新评论