2017-06-15 33 views
0

我想強制HTTPS爲我的網站之一。不幸的是,我的服務器上有其他網站,我不想將它們重定向到https。我試圖添加一個重寫條件,但它不工作。你知道爲什麼嗎?我的目標是避免botletter.com的https重定向.htaccess重寫強制HTTPS,如何避免一些域名?

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} !http://botletter.com [NC] 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteCond %{HTTP_HOST} !http://www.botletter.com [NC] 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] 

謝謝。

+0

而不是使用動態配置文件( 「',htaccess'」)將該規則放置在您的http服務器主機配置中。事情甚至更快。您可以創建一個單獨的文件來保存這些規則,並將其包含在所需的所有虛擬主機定義中。 – arkascha

回答

1

您可以使用:

RewriteEngine on 

# To https www 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteCond %{HTTP_HOST} !(botletter\.com|eedart\.co|other\.com) [NC] 
RewriteRule^https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

# To https 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} !(botletter\.com|eedart\.co|other\.com) [NC] 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

# botletter to www.botletter 
RewriteCond %{HTTP_HOST} ^(botletter\.com|eedart\.co|other\.com) [NC] 
RewriteRule^http://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301] 

根據您的配置,您可能需要使用:
RewriteCond %{HTTP:X-Forwarded-Proto} !https,而不是RewriteCond %{HTTPS} off

+1

謝謝,它的工作原理!我如何添加其他域名以避免?我可以在RewriteCond%{HTTP_HOST}後添加一行像RewriteCond%{HTTP_HOST}!feedart.co [NC]!botletter.com [NC](它似乎不起作用) – AlphaNico

+0

我改變了我的代碼。 – Croises

+1

完美,它的作品!再次感謝。 – AlphaNico