的.htaccess 301重定向子域到另一个,多个顶级域名 [英] .htaccess 301 redirect one subdomain to another, for multiple TLDs
问题描述
我想改变我的网站的一个子域,并想使我使用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
因此,基本上,我需要检测 subold
的presence主机,更改为 subnew
并重定向到这个新的子域任何TLD用户试图访问,preserving。
目前的一刻,我的规则如下:
的RewriteCond%{HTTP_HOST} ^ subold.domain.local [NC]
(。*)重写规则^ $ HTTP://subnew.domain.local/$1 [L,R = 301]
的RewriteCond%{HTTP_HOST} ^ subold-staging.domain.local [NC]
(。*)重写规则^ $ HTTP://subnew-staging.domain.local/$1 [L,R = 301]
的RewriteCond%{HTTP_HOST} ^ subold.domain.com [NC]
重写规则^(。*)$ http://subnew.domain.com/$1 [L,R = 301]
的RewriteCond%{HTTP_HOST} ^ subold-staging.domain.com [NC]
重写规则^(。*)$ http://subnew-staging.domain.com/$1 [L,R = 301]
的RewriteCond%{HTTP_HOST} ^ subold.domain.co.uk [NC]
重写规则^(。*)$ http://subnew.domain.co.uk/$1 [L,R = 301]
的RewriteCond%{HTTP_HOST} ^ subold-staging.domain.co.uk [NC]
重写规则^(。*)$ http://subnew-staging.domain.co.uk/$1 [L,R = 301]
假设有 subold刚VS您的真实域名subnew
的差异。
您只需要一个这样的规则:
的RewriteCond%{HTTP_HOST} ^ subold \。(。+)$ [NC]
重写规则^的http://subnew.%1% {REQUEST_URI} [L,R = 301]
I want to change a subdomain of my site and would like to make the RewriteRules I use to 301 users more simple, as currently I have to have multiple rules to cover various eventualities.
Is there a way that with one rule I can do the following:
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
So basically, I need to detect the presence of subold
in the host, change this to subnew
and redirect to this new subdomain, preserving whichever TLD the user tried to access.
At the minute, my rules are as follows:
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]
Assuming there is just a difference of subold vs subnew
in your real domain names.
You can have just one rule like this:
RewriteCond %{HTTP_HOST} ^subold\.(.+)$ [NC]
RewriteRule ^ http://subnew.%1%{REQUEST_URI} [L,R=301]
这篇关于的.htaccess 301重定向子域到另一个,多个顶级域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!