简体   繁体   中英

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

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM