【问题标题】:Force all pages to HTTPS强制所有页面使用 HTTPS
【发布时间】:2013-11-12 10:48:24
【问题描述】:

我正在使用带有 SSL 的 Heroku php。一切都已设置好,https 完美运行。 我的域名托管在 Godaddy。 Heroku 作为 apache 网络服务器。 但是http://mysite.com,www.mysite.com 不会重定向到https://www.mysite.com 这就是我想要的。

我已将 .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

【问题讨论】:

标签: php apache heroku


【解决方案1】:
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

【讨论】:

  • 我已经把它从 apache wiki 中拉了出来,假设它应该可以工作。如果您有权访问虚拟主机配置,请使用this
【解决方案2】:

使用 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']}"));

两者都应该工作。 :-)

【讨论】:

    猜你喜欢
    • 2014-01-22
    • 2020-07-03
    • 2021-03-22
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-01
    • 2016-06-02
    相关资源
    最近更新 更多