2013-10-17 30 views
7

如何強制SSL特定域目前我有htaccess的力SSL特定域

RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

這是工作,但我有幾個在域添加在我的主機,當我嘗試訪問其他附加域,附加域也被迫使用SSL。

我嘗試這樣做:

RewriteCond %{HTTP_HOST} ^exampledomain\.org$ [OR] 
RewriteCond %{HTTP_HOST} ^www\.exampledomain\.org$ 
RewriteRule ^/?$ "https\:\/\/www\.examplemydomain\.org\/" [R=301,L] 

但它給我一個無限循環。

回答

16

這應該工作:

RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} exampledomain\.org$ [NC] 
RewriteRule^https://www.examplemydomain.org%{REQUEST_URI} [R=301,L,NE] 
+1

哇,那個工作...... tnx人。 Kodos –

+1

插入符號和目標地址之間的空間相當重要;-)我學會了一件事,部分是通過反覆試驗。 –

+0

@anubhava子域如何?例如:sub.exampledomain.com –

0

嘗試:

RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(www\.){0,1}exampledomain\.org$ 
RewriteRule ^/?$ "https\:\/\/www\.examplemydomain\.org\/" [R=301,L] 
2

它看起來就像你在這裏做2分不同的事情。缺少一個時,您將添加www,並且在未使用SSL時強制使用SSL。所以有兩種不同的條件,一個是正確的應該強制重定向。這意味着你想使用[OR]標誌,但是如果請求是已經是SSL,那麼你使用它的方式會中斷。嘗試:

RewriteCond %{HTTP_HOST} ^exampledomain\.org$ [OR] 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://www.examplemydomain.org/$1 [R=301,L]