Http to Https redirect for wordpress on heroku

2019-07-17 17:25发布

I'm trying to redirect all webpages to https for my wordpress app which is hosted on heroku. 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. 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. I also tried adding '/' to the HTTPS plugin URL filters, but this didn't work either. All my attempts to add php code to the actual page just ends up in an infinite redirect.

2条回答
Emotional °昔
2楼-- · 2019-07-17 17:45

Looks like the thing that was getting me was the order in 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.

查看更多
够拽才男人
3楼-- · 2019-07-17 18:05

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

查看更多
登录 后发表回答