2013-11-01 99 views
0

我使用Heroku PHP與SSL上。一切安裝和HTTPS完美。 我的域名託管於Godaddy。 Heroku作爲apache web服務器。 但http://mysite.com,www.mysite.com將不會重定向到https://www.mysite.com 這就是我想要的。強制所有頁面HTTPS

我改變了.htaccess文件到以下

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteCond %{REQUEST_URI} protected [NC,OR] 
RewriteCond %{REQUEST_URI} protected2 [NC,OR] 
RewriteCond %{REQUEST_URI} protected3 [NC] 

我也向前域https://www.mysite.com

+0

你可以添加轉發規則嗎? – Qben

+0

看到這個(它適用於我):https://stackoverflow.com/questions/31467871/setting-up-https-redirects-on-heroku-laravel-instance# – Onthemail

回答

0
RewriteEngine On 
# This will enable the Rewrite capabilities 

RewriteCond %{HTTPS} !=on 
# This checks to make sure the connection is not already HTTPS 

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L] 
# This rule will redirect users from their original location, to the same location but using HTTPS. 
# i.e. http://www.example.com/foo/ to https://www.example.com/foo/ 
# The leading slash is made optional so that this will work either in httpd.conf 
# or .htaccess context 

Source

+0

它抱怨 - 太多循環 – user1688346

+0

我已經拉它離開了apache wiki,假設它能工作。如果您有權訪問虛擬主機配置,請使用[this](http://wiki.apache.org/httpd/RedirectSSL) – alandarev

0

使用htaccess文件:

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R,L] 

使用PHP引導:

exit(header("location: https://{$_SERVER['SERVER_NAME']}{$_SERVER['REQUEST_URI']}")); 

兩者都應該工作。 :-)

相關問題