Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

removing parameters from url

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

like image 734
Andy Avatar asked Dec 27 '10 07:12

Andy


2 Answers

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

like image 166
Mark Avatar answered Sep 17 '22 07:09

Mark


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]
like image 20
ZalemCitizen Avatar answered Sep 18 '22 07:09

ZalemCitizen