I'm trying to redirect language URLs that end with /?lang=da
, /?lang=de
and /?lang=nl
to the same URL but ending in /?lang=en
.
So
www.example.com/accommodation/hotel-room-1/?lang=da
should result in
www.example.com/accommodation/hotel-room-1/?lang=en
etc.
Is there a way to use wildcards for this?
If these language versions don't exist anymore then you can implement a redirect using mod_rewrite in your root
.htaccess
file.For example, near the top of your
.htaccess
file try the following:This 301 redirects
/<anything>?lang=da
(orde
ornl
) to the same URL-path but withlang=en
. As in your example,/accommodation/hotel-room-1/?lang=da
redirects to/accommodation/hotel-room-1/?lang=en
.The
$1
backreference captures the URL-path from the requested URL.Note that it's preferable to first test with 302 (temporary) redirects to avoid caching any erroneous redirects and only change to 301 when you are sure it's working as intended.