removing parameters from url

2020-07-18 07:56发布

问题:

i want to remove a parameter after the true url then redirection to the same url without this parameter

example :

i want to remove the parameter "r" from

http://www.mysite.com/123.html?r=1

and redirection to

http://www.mysite.com/123.html

using htaccess and 301 redirect

thank you

回答1:

Try this:

RewriteRule ^123.html.? 123.html? [L]

Note how the second url ends with a ?, this removes the query string.

Source: http://wiki.apache.org/httpd/RewriteQueryString



回答2:

Better than using a final ?, you should use the qsdiscard flag QSD, and the permanent redirect flag R=301. So for your example :

RewriteRule ^123\.html(.*)$ 123.html [QSD,L,R=301]