0

We had a version of our website which added a lang query parameter to the end of any URL. It didn't last long as it created lots of duplicate pages... but they still exist in google. I'd like to do a redirect to basically remove ANY of the references.

An example is https://www.example.com/?lang=au

I am using a redirection plugin (wordpress) which supports regex, however I am having trouble with the formatting. It's removing the "Lang" part, but nothing else.

/(.*)\/?lang=*

That should then redirect to

https://www.example.com/$1 

So any form eg: example.com/sub-page/something-else/?lang=au would redirect back to example.com/sub-page/something-else/ (minus the lang param).

Thanks for any help!

2
  • try /(.*)\/?lang=.* Commented Mar 13, 2019 at 9:25
  • Try with following /(.*)\/?lang=([^]*) Commented Mar 13, 2019 at 9:31

1 Answer 1

1

This is the regex you should use:

\/(.*)\/\?lang=.*

Basically you were using =* at the end of yours which means: Matches between zero and unlimited times the = character and that wasn't be able to match anything after =.

Using lang=.* means:

  • lang= matches the characters lang= literally (case sensitive)
  • .* matches any character (except for line terminators)
Sign up to request clarification or add additional context in comments.

4 Comments

Works nicely thank you - it does seem to leave a ? behind though - is there any way to remove that too? Might get complicated though if there are other parameters? (though I don't think they are used on the site so it might not be an issue)
Edited the regex on my answer, give it a try! :) I replaced ? with \? since it needs an escape to match the character literally.
Let me know if you need any help on handling other parameters, we will try to find a solution
Worked fantastically. thank you for the answer - and also the explanation :)

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.