You’ve been using the WPML setting that adds a query parameter at the end of a URL to select the language
and now you want to switch to the setting where the languages are in directories?
From this setting: Language name added as a parameter (https://www.example.com?lang=fr – French)
To this setting: Different languages in directories ((https://www.example.com/ – English, https://www.example.com/fr/ – French))
Then the below redirect rule is for you. It safely redirects all old URLs to the new ones, after you did the switch.
Comments 4
Thanks Aleksandar!!!
Your rule has been very helpful to redirect urls with language parameters.
Greetings
Author
Hi Ernesto
Thanks for reporting this! I’m glad it helps you.
Aleks
Thanks for solution!
But this thing also will break the /wp-admin/ part, because it contains lang=* when you switch language.
working solution is
RewriteEngine On
# redirect from ?lang=nl to /nl/
RewriteCond %{QUERY_STRING} \?lang=(..) [NC]
RewriteCond %{REQUEST_URI} !wp-admin [NC]
RewriteRule ^(.*\/)|^$ /%1/$1? [L,R=301]
Author
Hi Konstantin
You are right. Thanks for letting me know. I’ve updated the gist.
Have a good day!
Regards
Aleks