简体   繁体   中英

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. 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.

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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