1

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?

MrWhite
  • 13,315
Kneops
  • 13

1 Answers1

0

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:

RewriteEngine On

RewriteCond %{QUERY_STRING} ^lang=(da|de|nl)$ RewriteRule (.*) /$1?lang=en [R=301,L]

This 301 redirects /<anything>?lang=da (or de or nl) to the same URL-path but with lang=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.

MrWhite
  • 13,315