0

My Wordpress site's URL is set to HTTPS in the WP settings. If you type domain.com, it redirects to www.domain.com. If you click on the logo, it'll take you to https:/www.domain.com. I'd like https to be enabled by default on all pages.

I tried using this as Brandozz recommended and it turns out my caching plugin as well but it keeps causing the loop error.

 RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

My server used Nginx. The caching plugin is recommending adding a few lines of code but I'm not sure where or how. See http://docs.wp-rocket.me/article/36-fix-for-ssl-redirection-issue.. Cloudways is my host and I'm on a DigitalOcean server.

Moyed Ansari
  • 8,436
  • 2
  • 36
  • 57
Mr.988
  • 1
  • 2
  • 1
    possible duplicate of [Redirect non-www and non-https to https://www](http://stackoverflow.com/questions/22895260/redirect-non-www-and-non-https-to-https-www) – arco444 Sep 14 '15 at 14:54

3 Answers3

0

Here is what I'm currently using to redirect everything to https

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
brandozz
  • 1,059
  • 6
  • 20
  • 38
  • Cool, thanks. Are you using this for a Wordpress site? If so, do you have the wordpress url set to https as well? I experienced a loop error a few weeks back and I had to delete my htaccess which solved the problem. Then, I put back my old htaccess and it's still working fine. Not sure what the problem was but I'm hoping it doesn't cause any more issues. edit: typo – Mr.988 Sep 14 '15 at 15:02
  • Just tried it.. It caused the site not to load.. redirect loop it said. – Mr.988 Sep 14 '15 at 15:08
  • Yes, this is a WordPress site and in my settings the url is set to https. – brandozz Sep 14 '15 at 15:29
  • That's great to know. My caching plugin must be causing the issues then. I've had nothing but trouble since I got it but my site is faster than before so I kept it. I'm using WP Rocket. – Mr.988 Sep 14 '15 at 15:34
  • I've never used WP Rocket but it looks like a well supported plugin. Maybe you can reach out to them for support. Did disabling the plugin fix the redirect loop issue? – brandozz Sep 14 '15 at 17:04
  • Yes, it's a great plugin and their support is just as good but the time difference and language barrier makes it a bit hard to get things done. I didn't have to disable the plugin, deleting the htaccess file gets the site back up. Then I reupload a copy of the htaccess and it keeps working fine until I try to add the redirection code. This isn't my first attempt at trying to resolve this issue. I did reach out to my host (totally useless support), MaxCDN, my cdn provider(can't thank them enough - they go above and beyond their duties), and cache plugin devs and that led me nowhere. – Mr.988 Sep 14 '15 at 18:15
  • The odd thing is that I already have a non-www to http www redirect code that I had displayed in my OP above (but took it out in an edit like a fool).. I was deleting my existing redirect code and replacing it with what you recommended or with other codes that I found and they all end up with the same loop error msg. I got a headache again from this bs. Time to sleep on it for a while (again). Thanks for the help though! – Mr.988 Sep 14 '15 at 18:19
0
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Tunaki
  • 132,869
  • 46
  • 340
  • 423
0

RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]