derdida
derdida

Reputation: 14904

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!

Upvotes: 4

Views: 10516

Answers (1)

goodeye
goodeye

Reputation: 2449

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

Upvotes: 7

Related Questions