I am trying to remove a specific query parameter from my URL. In my case I would only like to remove the code=blahblah and do this in htaccess.
For example if my URL is http://www.foo.com/project/index.php/current-page?code=blahblah
I need it do become http://www.foo.com/project/index.php/current-page
I do not want to get rid of all query parameters though eg. http://www.foo.com/project/index.php/current-page?id=67&code=blahblah
I need it to become http://www.foo.com/project/index.php/current-page?id=67
You can use REGEX :
(https?:\/\/[^?]*\??.*?)([&?]code=[^ &]*)(.*)
And replace with : \1\3
In Htaccess :
RewriteEngine On
RewriteRule (https?:\/\/[^?]*\??.*?)([&?]code=[^ &]*)(.*) /$1$3 [L,R=301]
You can use this rule for removal of code=blahblah
from anywhere in the query string:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^(.*?&)?code=blahblah(?:&(.*))?$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R,L]