Because of removing several languages from a multi-language website, I need to 301 redirect pages that end with ?lang=da, ?lang=de, and ?lang=nl to the same URLs but ending in ?lang=en. It sounds like a common scenario, but I haven't found the right code yet to accomplish this or tried some code because the purpose of that code was either to redirect to one new URL or to replace the URL but not the query string, while I need to replace the query string and keep the URL.
-
1Welcome to SO, please do share your tried htaccess rule file in your question, thank you.RavinderSingh13– RavinderSingh132021-02-01 10:54:00 +00:00Commented Feb 1, 2021 at 10:54
1 Answer
This probably is what you are looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^lang=(da|de|nl)$
RewriteRule ^ %{REQUEST_URI}?lang=en [QSD,R=301,END]
For this to work the rewriting module obviously needs to be loaded into your http server and it has to be activated for your http host too.
It is a good idea to start out with a 302 redirection and to only change that into a 301 once you are convinced everything is set up as required. That way you prevent ugly caching effects...
You can implement such rules in the http server's host configuration. Or, if you do not have access to that, you can use a distributed configuration file (".htaccess"), but that has performance disadvantages and you also need to enable the interpretation of such files first. Please see the documentation of the tool you are using to learn how to do that.
4 Comments
https://www.ullstorp.se/$%7bREQUEST_URI%7d?lang=en This is the current htaccess file: # REDIRECT <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{QUERY_STRING} ^lang=(da|de|nl)$ RewriteRule ^ ${REQUEST_URI}?lang=en [QSD,R=302,END] </IfModule> # END REDIRECT%{REQUEST_URI}, not ${REQUEST_URI}, my fault. However: please note that you are expected to understand what this is about. You are expected to know the tools you are working with. You are expected to read the documentation of those tools. Which all means you definitely should have been able to sort that out yourself. Just blindly copying things without understanding what you are doing is not a strategy. Apart from that: good luck!