2017-05-25 130 views
3

目前我使用http://example.com但我希望所有重定向到http 小號:// WWW .example.com的重定向到https://www.example.com

我讀到這裏的幾個主題和嘗試了很多解決方案,但沒有爲我工作。

我的最後一次嘗試是這樣的:

RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteCond %{HTTPS} off 
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTP_HOST} !^www\. [NC] 
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

當我使用此代碼,我可以看到這一點: enter image description here

但它給了我這個消息也:

的頁面沒有正確重定向。 Firefox檢測到 服務器正在重定向該地址的請求,其方式 從未完成。

你能幫我嗎?

回答

0

與您的域名替換示例並嘗試

RewriteEngine On 
RewriteCond %{HTTP_HOST} ^example\.com [NC] 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L] 
0

在我看來,你還試圖迫使WWW。你可以在你的.htaccess使用這種一舉兩得:

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

將這個規則你.htaccess文件的頂部,並確保您清除緩存你測試之前。

1

你應該嘗試另一種解決方案,如redirect.center,這很容易。只需配置您的DNS如下:

example.com A 54.84.55.102 
redirect.example.com CNAME www.example.com.opts-https.opts-uri.redirect.center 

完成!