2015-05-05 42 views
0

我想重定向: 1)http://example.comhttps://www.example.com 2)http://www.example.comhttps://www.example.com的.htaccess:HTTP來HTTPS重定向不工作

但是我的.htaccess往往會忽略%{} HTTPS在...的RewriteCond因此 我無法處理第二個提到的情況,它給我循環重定向錯誤消息。

的.htaccess如下:

# Redirect non-www urls to www 
RewriteEngine on 

RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^www.example\.com/?$ 
RewriteRule ^(.*)$ https://www.example.com [NC,R=301] 

RewriteCond %{HTTP_HOST} ^example\.com/?$ 
RewriteRule ^(.*)$ https://www.example.com [NC,R=301] 

RewriteCond %{HTTP_HOST} ^example\.com\?.*$ 
RewriteRule ^(.*)$ https://www.example.com/$1 [NC,R=301] 

我會盡量說的很不錯謝謝!任何人都可以幫助我解決這個問題。

回答

0

你真正需要的只是你想要的一個規則。

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC,OR] 
RewriteCond %{HTTPS} !^on 
RewriteRule ^(.*)$ https://www.example.com [NC,R=301,L] 
+0

獲取循環重定向:( – Benji

+0

清除瀏覽器的緩存或嘗試在其他瀏覽器中,該規則有效。 –