Reputation: 175
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
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
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