2013-11-01 150 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']}")); 

两者都应该工作。 :-)

相关问题