简体   繁体   English

Http到Https在Heroku上进行Wordpress重定向

[英]Http to Https redirect for wordpress on heroku

I'm trying to redirect all webpages to https for my wordpress app which is hosted on heroku. 我正在尝试将所有网页重定向到托管在heroku上的我的wordpress应用程序的https。 I'm using the Wordpress HTTPS plugin, and I've succeeded in getting all the wordpress pages to redirect to https, but my custom pages do not redirect. 我正在使用Wordpress HTTPS插件,并且已成功使所有wordpress页面重定向到https,但是我的自定义页面未重定向。 The app is setup using this template . 该应用程序是使用此模板设置的。 It seems like people traditionally do this by editing the .htaccess file (for example here ), but I can't seem to get that to work. 看来人们传统上是通过编辑.htaccess文件来完成此操作的(例如here ),但我似乎无法使它正常工作。 I also tried adding '/' to the HTTPS plugin URL filters, but this didn't work either. 我还尝试在HTTPS插件URL过滤器中添加“ /”,但这也不起作用。 All my attempts to add php code to the actual page just ends up in an infinite redirect. 我所有将php代码添加到实际页面的尝试都以无限重定向结束。

Looks like the thing that was getting me was the order in htaccess. 看起来让我着迷的是htaccess中的命令。 Everything works now and my file looks like this 现在一切正常,我的文件如下所示

# 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

It was important to put the https rule first, which I hadn't done originally. 首先将https规则放在首位是很重要的,而我最初并未这样做。

This should work: 这应该工作:

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

This checks to see if https is not on (so if it is off) then redirect the request to https 这将检查https是否未打开(如果已关闭),然后将请求重定向到https

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM