Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect only with specific domain

I have a website with 2 different domains, for example:

www.example.com www.example.net

Now i want, that every user coming from example.com should be redirected to www.example.de

Ill tried:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^example\.com$
RewriteRule ^.*$ http://example.de/$0 [L,QSA,R=301]

But now still all users from example.net get redirected to example.de

How can i solve that, that only users from example.com gets redirected (also with all subfolders).

Thanks!

like image 222
derdida Avatar asked Mar 15 '23 13:03

derdida


1 Answers

Try this - you want to match example.com (remove the !), and it's clearer to capture the incoming url into $1.

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*)$ http://example.de/$1 [L,QSA,R=301]

Also, while debugging, change the R=301 to R, so your browser doesn't "stick" with an old rule. When it works, change it back to R=301

like image 146
goodeye Avatar answered Apr 26 '23 10:04

goodeye