1

Currently I am trying to remove query strings from multiple different URL's.

What I am using at the moment to remove "?cp=true" is

RewriteCond %{THE_REQUEST} \?cp=true\sHTTP [NC]
RewriteRule ^ %{REQUEST_URI} [L,R,QSD]

However this removes that query string from all pages with that query string. I want to only target a specific page e.g.

(/folder/another-folder/this-page)

Another change I would prefer to do, however not essential is to be able to remove any query string and not just "?cp=true". How would I go about doing this.

Thanks

1 Answer 1

1

I want to only target a specific page e.g./folder/another-folder/this-page

In that case you can include this URL in your RewriteCond before ?:

RewriteCond %{THE_REQUEST} /folder/another-folder/this-page\?cp=true\sHTTP [NC]
RewriteRule ^ %{REQUEST_URI} [L,R=302,NE,QSD]

If you want to remove all query strings then use:

RewriteCond %{THE_REQUEST} /folder/another-folder/this-page\? [NC]
RewriteRule ^ %{REQUEST_URI} [L,R=302,NE,QSD]
Sign up to request clarification or add additional context in comments.

2 Comments

Many thanks, that worked perfectly. One more question, I have URL's with only a ? in front of the URL. How would I go about removing the single question mark. An example URL is: /folder/another-folder/this-page? How can I change this to just "/folder/another-folder/this-page"
I have edited 2nd rule. It will take care of empty ? as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.