繁体   English   中英

.htaccess 301将一个子域重定向到另一个,用于多个TLD

[英].htaccess 301 redirect one subdomain to another, for multiple TLDs

我想更改站点的子域,并希望使对301个用户使用的RewriteRules更简单,因为当前我必须有多个规则来解决各种可能的情况。

有没有一种方法可以用一条规则执行以下操作:

subold.domain.com -> subnew.domain.com
subold.domain.co.uk -> subnew.domain.co.uk
subold.domain.local -> subnew.domain.local
subold-staging.domain.com -> subnew-staging.domain.com
subold-staging.domain.co.uk -> subnew-staging.domain.co.uk
subold-staging.domain.local -> subnew-staging.domain.local

因此,基本上,我需要检测主机中存在subold ,将其更改为subnew并重定向到此新的子域,以保留用户尝试访问的任何TLD。

目前,我的规则如下:

RewriteCond %{HTTP_HOST} ^subold.domain.local [NC]
RewriteRule ^(.*)$ http://subnew.domain.local/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^subold-staging.domain.local [NC]
RewriteRule ^(.*)$ http://subnew-staging.domain.local/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^subold.domain.com [NC]
RewriteRule ^(.*)$ http://subnew.domain.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^subold-staging.domain.com [NC]
RewriteRule ^(.*)$ http://subnew-staging.domain.com/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^subold.domain.co.uk [NC]
RewriteRule ^(.*)$ http://subnew.domain.co.uk/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^subold-staging.domain.co.uk [NC]
RewriteRule ^(.*)$ http://subnew-staging.domain.co.uk/$1 [L,R=301]

假设您的真实域名中存在subold vs subnew的区别。

您只能有一个这样的规则:

RewriteCond %{HTTP_HOST} ^subold\.(.+)$ [NC]
RewriteRule ^ http://subnew.%1%{REQUEST_URI} [L,R=301]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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