Nerses
Nerses

Reputation: 749

ModRewrite redirect dynamic sub-domains

I'm trying to achieve the following :

when user is trying to access "user1.domain.com"

I'd like to redirect to : "user1.anotherdomain.com"

I've tried this rule, but that didn't work

RewriteRule ^(.*).domain.com$ $1.anotherdomain.com [R=301,NC]

Any help is much appreciated!

Upvotes: 1

Views: 61

Answers (1)

Martin
Martin

Reputation: 38309

Sounds like this ought to work:

RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com$ [NC]
RewriteRule ^/(.*)$ http://%1.anotherdomain.com/$1 [R=301]

Upvotes: 1

Related Questions