Reputation: 1
I've read all tutorials about .htaccess
and still don't know:
.htaccess
looks now in that way:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*domain.com$ [NC]
RewriteRule ^(.*)$ http://anotherdomain.com/ [R=301,L]
I want to redirect:
subdomain.domain.com
To:
subdomain.anotherdomain.com
Not specifying subdomain.
So it should redirect:
subdomain1.domain.com
To:
subdomain1.anotherdomain.com
And:
subdomain2.domain.com
To:
subdomain2.anotherdomain.com
And:
subdomain3.domain.com
To:
subdomain3.anotherdomain.com
And so on...
Is it possible to pass subdomainx
to $1
and then redirect to $1.anotherdomain.com
?
Upvotes: 0
Views: 54
Reputation: 785108
You can use:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com$ [NC]
RewriteRule ^ http://%1.anotherdomain.com%{REQUEST_URI} [R=301,L,NE]
Upvotes: 1