我正在将网站迁移到新域,并且在使用301重定向时需要整个结构(子域和域)保持完整。
http://example.com/test/page 至 http://example2.com/test/page
也
http://wildcard.example.com/test/page/random 至 http://wildcard.example2.com/test/page/random
答案 0 :(得分:1)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^http://example.com/test/page [NC]
RewriteRule ^(.*)$ http://example2.com/test/page [L,R=301,NC]
和
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]
你可以使用它
答案 1 :(得分:0)
我找到的最简单的解决方案是......
对于主域名:
RewriteCond%{HTTP_HOST} ^ example.com [NC]
RewriteRule ^(。*)$ http://example2.com/ $ 1 [L,R = 301]
对于每个子域名:
RewriteCond%{HTTP_HOST} ^ each-subdomain.example.com [NC]
RewriteRule ^(。*)$ http://each-subdomain.example2.com/ $ 1 [L,R = 301]