我用它来重写https我的.htaccess文件的所有调用。
我想避免将http://foo.myhost.com重写为 https://www.myhost.com
它应该留下来
http://foo.myhost.com< -note,甚至不是https
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
答案 0 :(得分:2)
添加否定条件以避免匹配子域:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^(?!www\.)[^.]+\.myhost\.com$ [NC]
RewriteRule ^ https://www.myhost.com%{REQUEST_URI} [L,R=301]