我想将http://
,http://www.
https://www.
和不存在的子域变体重写为https://domain.com
。不存在的子域变体可能是http://abc.domain.com
和https://abc.domain.com
。更复杂的是,我想保留尾随的URL,并防止重定向现有的子域。并且,一些现有子域使用http,而其他子域使用https。
这是我到目前为止所做的:
#don't redirect existing subdomains example1 or example2
RewriteCond %{HTTP_HOST} ^((example1|example2)\.)?domain\.com$
RewriteRule .* - [L]
##redirect http, wildcard subdomains, and www. with appended trailing URLs
RewriteCond %{HTTP_HOST} . [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://domain.com/$1 [R=301,L]
提前致谢。
答案 0 :(得分:0)
以下是重定向nonexistent subdomains to https://domain.com
的方法:
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteCond %{HTTP_HOST} !^(valid1|valid2|valid3)\.domain\.com$
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]