1

I need to redirect only this URL https://www.mywebsite.com/?lang=en to https://www.mywebsite.com/en/

I try with this without success

RewriteCond %{REQUEST_URI} https://www.mywebsite.com/  
RewriteCond %{QUERY_STRING} lang=en
RewriteRule ^(.*)$ https://www.mywebsite.com/en/ [R=301,L]

1 Answer 1

1

You need to put an empty question mark ? at the end of your rule's destination to discard old query string from the new url .

To redirect /?lang=en to /en/ you can use the following rule:

RewriteEngine on
RewriteCond %{QUERY_STRING} lang=en
RewriteRule ^$ https://www.mywebsite.com/en/? [R=301,L]

Otherwise your new url would look something like /en/?lang=en .

Clear your browser cache before testing this.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks this work, and is there a generic way perhaps to auto redirect mywebsite.com/something/?lang=en to mywebsite.com/en/something ?
@Laurent you can use : RewriteEngine on RewriteCond %{QUERY_STRING} lang=en RewriteRule ^.*$ https://www.mywebsite.com/en%{REQUEST_URI}? [R=301,L]
Yes it work and sorry if i have in old url the .html mywebsite.com/something.html?lang=en to remove it to have only mywebsite.com/en/something

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.