.htaccess重定向到HTTPS,但子域除外

时间:2012-05-28 19:31:29

标签: .htaccess

我想将所有非https请求重定向到https除了对子域的请求。例如

http://example.com/  =>  https://example.com/
http://example.com/page  =>  https://example.com/page

但是

http://m.example.com/  REMAINS  http://m.example.com/

这就是我在.htaccess中所拥有的内容,它重定向所有请求(包括子代码):

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

我知道我必须在RewriteRule之前添加条件,但我对语法不太确定。

2 个答案:

答案 0 :(得分:17)

RewriteCond

之前添加另一个RewriteRule
RewriteCond %{HTTP_HOST} !=m.example.com

答案 1 :(得分:1)

要从https重写中排除任何子域,请添加

RewriteCond %{HTTP_HOST} !=/(.*?)/.example.com