Remove parameter from URL viac .htaccess

2020-04-21 05:21发布

问题:

I need advice how to remove a parameter from the url using. Htcaccess

The condition is as follows:

redirect url from:

http://example.com/?movie=2&ref=nf

to:

http://example.com/?movie=2

I tried several options but I have not come to nothing

Thank you for your ideas / advice.

THX.

回答1:

Try adding the following to the .htaccess file in the root directory of your site.

RewriteEngine on
RewriteBase / 

#If request contains ref param
RewriteCond %{THE_REQUEST} \?([^&\ ]+)&ref=  [NC]  
#redirect to URL without the ref param
RewriteRule ^  %{REQUEST_URI}?%1 [L,R=301]