Kieran Headley
Kieran Headley

Reputation: 667

Redirect rule to remove query string from url using RedirectMatch

I am looking to redirect all pages on a website by removing any that contain ?cont= within the URL using RedirectMatch 301.

For example; /my-page.html?cont=uk would 301 redirect to /my-page.html

however this needs to also work for URL's with multiple query strings in; /my-page.html?cont=uk&size=100 would 301 redirect to /my-page.html?size=100

If needed I can supply all of the variations of what cont= can be, there are around 25. Is this possible?

Upvotes: 1

Views: 106

Answers (1)

anubhava
anubhava

Reputation: 785156

You can use this rule as your very first rule in site root .htaccess to remove cont= parameter from any position:

RewriteEngine On

RewriteCond %{THE_REQUEST} \?(.*&)?cont=[^&]*&?(\S*)\sHTTP [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,NE,L]

# rest of your rules go here

Upvotes: 1

Related Questions