Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex .htaccess 301针对多个TLD将一个子域重定向到另一个子域_Regex_Apache_.htaccess_Redirect_Mod Rewrite - Fatal编程技术网

Regex .htaccess 301针对多个TLD将一个子域重定向到另一个子域

Regex .htaccess 301针对多个TLD将一个子域重定向到另一个子域,regex,apache,.htaccess,redirect,mod-rewrite,Regex,Apache,.htaccess,Redirect,Mod Rewrite,我想改变我的网站子域,并希望使我使用301用户的重写规则更简单,因为目前我必须有多个规则,以涵盖各种可能性 有没有一种方法可以通过一条规则做到以下几点: 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-

我想改变我的网站子域,并希望使我使用301用户的重写规则更简单,因为目前我必须有多个规则,以涵盖各种可能性

有没有一种方法可以通过一条规则做到以下几点:

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
因此,基本上,我需要检测主机中是否存在
subld
,将其更改为
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]

假设您的真实域名中只有
子域名与子域名的差异

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

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