removing parameters from url

白昼怎懂夜的黑 提交于 2020-01-01 12:01:15

问题


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]


来源:https://stackoverflow.com/questions/4537281/removing-parameters-from-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!