我有这段代码,但效果不好: 我希望omly HTTP到a-subdomain,只有HTTPS到subdomain ....
使用基于@Dusan Bajic的更改代码进行编辑:
#Trying to force https, this works...
RewriteCond %{HTTPS} !=on [NC]
RewriteCond %{HTTP_HOST} !^a-subdomain\.domain\.com$ [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
#Trying to force http, not works...
RewriteCond %{HTTPS} =on [NC]
RewriteCond %{HTTP_HOST} ^a-subdomain\.domain\.com$ [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [NC,R=301,L]
子域名重定向到HTTPS - 没关系。
可以通过HTTP访问a-subdomain - 没关系
a-subdomain继续通过HTTPS访问 - 不确定。
答案 0 :(得分:0)
使用RewriteCond语法:
RewriteCond TestString CondPattern [flags]
CondPattern
(在没有任何前缀的情况下使用时)是perl兼容的正则表达式。
以=
为前缀,CondPattern
作为普通字符串处理,并按字典顺序与TestString
使用:
RewriteCond %{HTTP_HOST} =a-subdomain.domain.com
或
RewriteCond %{HTTP_HOST} ^a-subdomain\.domain\.com$