mod rewrite强制HTTPS + WWW

时间:2015-04-26 21:11:55

标签: .htaccess mod-rewrite

我目前正在使用以下内容强制www.,但我还要强制https

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

如何正确编辑以强制https AS WELL www.

修复了主网站:

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

其他域名现在被迫包含https我只希望我的主站点能够这样做...

主网站的不同修复:

RewriteEngine on
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^DOMAIN\.com$ [NC]
RewriteRule ^.*$ https://www.DOMAIN.com%{REQUEST_URI} [R,L]

似乎正常工作。我将其他域名移到了另一台服务器

1 个答案:

答案 0 :(得分:0)

以下规则可用于强制 <div id="DeltaPlaceHolderMain"> <a id="mainContent" tabindex="-1" name="mainContent"></a> <table width="100%"> <tbody> <tr> <td width="15%" valign="top"></td> <td width="85%" valign="top"></td> </tr> </tbody> </table> <table width="100%"></table> <table width="100%"></table> </div>www在同一规则中:

https

# https and www in one rule RewriteCond %{HTTP_HOST} !^www\. [NC,OR] RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [R=302,L,NE] 的排序非常重要,否则将无法正确捕获RewriteCond。前两个条件是或%1在一起,第三个条件是OR