user989990
user989990

Reputation: 175

301 Redirect Domain and Subdomains with htaccess

I am moving a site to a new domain and need the whole structure (of subdomains and domains) to stay intact while using a 301 redirect.

http://example.com/test/page to http://example2.com/test/page

also

http://wildcard.example.com/test/page/random to http://wildcard.example2.com/test/page/random

Upvotes: 0

Views: 2749

Answers (2)

Shuvo Shuvo
Shuvo Shuvo

Reputation: 329

RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://example.com/test/page [NC]
RewriteRule ^(.*)$ http://example2.com/test/page [L,R=301,NC]

and

RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://wildcard.example.com/test/page/random [NC]
RewriteRule ^(.*)$ http://wildcard.example2.com/test/page/random [L,R=301,NC]

you can use it

Upvotes: 1

user989990
user989990

Reputation: 175

The simplest solution I found was....

For the main domain:

RewriteCond %{HTTP_HOST} ^example.com [NC]

RewriteRule ^(.*)$ http://example2.com/$1 [L,R=301]

For each subdomain:

RewriteCond %{HTTP_HOST} ^each-subdomain.example.com [NC]

RewriteRule ^(.*)$ http://each-subdomain.example2.com/$1 [L,R=301]

Upvotes: 0

Related Questions