Http to Https redirect for wordpress on heroku


Http to Https redirect for wordpress on heroku

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

看起来让我

得到的是 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规则放在首位很重要,我最初没有这样做。

这应该有效:

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

这将检查https是否未打开(因此,如果它已关闭),然后将请求重定向到https