我的服务器。 htaccess规则如下所示:
RewriteEngine On
# first redirect
RewriteCond %{HTTP_HOST} ^www\.testing\.examplewebsite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^testing\.examplewebsite\.co\uk$ [NC]
RewriteRule ^(.*)$ https://testing.examplewebsite.com/$1 [L,R=301]
# second redirect
RewriteCond %{HTTP_HOST} ^www\.test\.examplewebsite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^test\.examplewebsite\.co\uk$ [NC]
RewriteRule ^(.*)$ https://test.examplewebsite.com/$1 [L,R=301]
# Main redirect
RewriteCond %{HTTP_HOST} ^www\.examplewebsite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^examplewebsite\.co\uk$ [NC]
RewriteRule ^(.*)$ https://examplewebsite.com/$1 [L,R=301]
# All subdomains that don't exist redirect
RewriteCond %{HTTP_HOST} ^(.+)\.examplewebsite\.co\.uk$ [NC]
RewriteRule ^ https://www.examplewebsite.com/ [L,R]
但由于某些原因,它没有导致服务器内部错误,我不确定它们是否都是100%正确。与最后一条规则一样,是否应该在开头使用^(.*)$
,在结尾使用$1
旗帜相同,不太确定它们是否都正确。
基本上我想做:
testing.examplewebsite.co.uk
和www.testing.examplewebsite.co.uk
转到https://testing.examplewebsite.com
test.examplewebsite.co.uk
和www.test.examplewebsite.co.uk
转到https://test.examplewebsite.com
examplewebsite.co.uk
和www.examplewebsite.co.uk
转到https://examplewebsite.com
stackoverflow.examplewebsite.co.uk
和www.stackoverflow.examplewebsite.co.uk
都发送到https://examplewebsite.com
答案 0 :(得分:2)
你在所有情况下都有拼写错误。您行中的第二个条件在.
之前缺少uk
。 ^ testing.examplewebsite.co.uk $ [NC]
RewriteEngine On
# first redirect
RewriteCond %{HTTP_HOST} ^www\.testing\.examplewebsite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^testing\.examplewebsite\.co\.uk$ [NC]
RewriteRule ^(.*)$ https://testing.examplewebsite.com/$1 [L,R=301]
# second redirect
RewriteCond %{HTTP_HOST} ^www\.test\.examplewebsite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^test\.examplewebsite\.co\.uk$ [NC]
RewriteRule ^(.*)$ https://test.examplewebsite.com/$1 [L,R=301]
# Main redirect
RewriteCond %{HTTP_HOST} ^www\.examplewebsite\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^examplewebsite\.co\.uk$ [NC]
RewriteRule ^(.*)$ https://examplewebsite.com/$1 [L,R=301]
# All subdomains that don't exist redirect
RewriteCond %{HTTP_HOST} ^(.+)\.examplewebsite\.co\.uk$ [NC]
RewriteRule ^ https://www.examplewebsite.com/ [L,R]