【问题标题】:Http to Https redirect for wordpress on herokuHeroku 上 wordpress 的 Http 到 Https 重定向
【发布时间】:2014-05-14 21:39:59
【问题描述】:

我正在尝试将托管在 heroku 上的 wordpress 应用程序的所有网页重定向到 https。我正在使用 Wordpress HTTPS 插件,并且已成功将所有 wordpress 页面重定向到 https,但我的自定义页面没有重定向。该应用程序是使用此template 设置的。似乎人们传统上通过编辑 .htaccess 文件(例如here)来做到这一点,但我似乎无法让它发挥作用。我还尝试将“/”添加到 HTTPS 插件 URL 过滤器,但这也不起作用。我所有将 php 代码添加到实际页面的尝试都以无限重定向结束。

【问题讨论】:

    标签: php wordpress .htaccess redirect heroku


    【解决方案1】:

    看起来让我印象深刻的是 htaccess 中的顺序。现在一切正常,我的文件看起来像这样

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    
    RewriteEngine On
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
    
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    </IfModule>
    # END WordPress
    

    将 https 规则放在首位很重要,我最初没有这样做。

    【讨论】:

      【解决方案2】:

      这应该可行:

      RewriteEngine On
      RewriteCond %{HTTPS} !=on
      RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
      

      这会检查https 是否未开启(如果关闭)然后将请求重定向到https

      【讨论】:

      • 这不起作用,因为它会导致和重定向循环(可能是因为 heroku?)我发现如果我将第二行更改为 "RewriteCond %{HTTP:X-Forwarded-Proto} !https " 它适用于 mysite.com,但不适用于 mysite.com/something
      猜你喜欢
      • 2016-09-01
      • 2013-02-13
      • 1970-01-01
      • 1970-01-01
      • 2021-08-31
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      • 2017-01-22
      相关资源
      最近更新 更多