1

I just installed an SSL on my Wordpress website and am now trying to redirect the entire site to https.

It seems to be working for me in Chrome, IE, Firefox, on my phone, etc, however, if I run my website through various online status checkers or site speed checkers, they all return an error and say my site is inaccessible. For example:

tools.pingdom.com - says my website has a redirect loop

isitdownrightnow.com - says my site is down

sitestatus.net - says my site has a 301 moved permanently error

And so on. So, something is obviously wrong. Here is my .htaccess code:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteRule ^(.*) https://www.low-caloriediet.com/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Redirect 301 /guest-post-guidelines https://www.low-caloriediet.com/contact
Redirect 301 /breakfasts-food https://www.low-caloriediet.com/food/breakfasts-food
Redirect 301 /lunch-dinners https://www.low-caloriediet.com/food/lunch-dinners
Redirect 301 /appetizers https://www.low-caloriediet.com/food/appetizers
Redirect 301 /snacks https://www.low-caloriediet.com/food/snacks
Redirect 301 /desserts-food https://www.low-caloriediet.com/food/desserts-food
Redirect 301 /low-calorie-drinks https://www.low-caloriediet.com/food/low-calorie-drinks
Redirect 301 /extras https://www.low-caloriediet.com/food/extras
Redirect 301 /calorie-granola https://www.low-caloriediet.com/food/calorie-granola
Redirect 301 /calorie-pasta https://www.low-caloriediet.com/food/calorie-pasta
Redirect 301 /calorie-chocolate https://www.low-caloriediet.com/food/calorie-chocolate
Redirect 301 /calorie-cookies https://www.low-caloriediet.com/food/calorie-cookies
Redirect 301 /calorie-yogurt https://www.low-caloriediet.com/food/calorie-yogurt
Redirect 301 /calorie-soup https://www.low-caloriediet.com/food/calorie-soup
Redirect 301 /calorie-muffins https://www.low-caloriediet.com/food/calorie-muffins
Redirect 301 /calorie-butter https://www.low-caloriediet.com/food/calorie-butter
Redirect 301 /calorie-pancakes https://www.low-caloriediet.com/food/calorie-pancakes
Redirect 301 /calorie-beer-alcohol https://www.low-caloriediet.com/food/calorie-beer-alcohol
Redirect 301 /calorie-oatmeal https://www.low-caloriediet.com/food/calorie-oatmeal
Redirect 301 /calorie-cereal https://www.low-caloriediet.com/food/calorie-cereal
Redirect 301 /calorie-bread https://www.low-caloriediet.com/food/calorie-bread
Redirect 301 /calorie-chips https://www.low-caloriediet.com/food/calorie-chips
Redirect 301 /calorie-crackers https://www.low-caloriediet.com/food/calorie-crackers

I can only assume theres something either wrong with or conflicting with this:

RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteRule ^(.*) https://www.low-caloriediet.com/$1 [R=301,L]

Since if I remove it I can access my site on tools.pingdom.com, etc. Any ideas whats going on? Thanks!

Edit: server is NGINX

Tmac
  • 311
  • 1
  • 16
  • Do you have `https` in site and home url inside wp-options table? – anubhava Aug 12 '14 at 07:06
  • @anubhava Yes, I do. – Tmac Aug 12 '14 at 11:40
  • "Edit: server is NGINX" - The above `.htaccess` file is Apache. Nginx is probably being used as a front-end proxy that handles the SSL (hence the requirement to check the `X-Forwarded-Proto` HTTP request header). Your site itself (on Apache) serves content over HTTP (port 80) to the Nginx proxy and Nginx serves SSL to the client. – MrWhite Jan 28 '17 at 11:12

2 Answers2

0
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This is taken from https://stackoverflow.com/a/13997498/3468562, which already has such an answer. :)

Community
  • 1
  • 1
0

Change your WP rules to this:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP:X-Forwarded-Proto} !^https$ [NC]
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

Make sure you have https in home and site URL inside WP permalink settings.

anubhava
  • 761,203
  • 64
  • 569
  • 643
  • There is no redirect loop in the rule. Open `firebug` and then visit your page to see what redirects you're getting in the Net tab. I suspect incorrect WP permalink settings. – anubhava Aug 12 '14 at 14:36
  • When I place your code int my htaccess, and run firebug it just says https:www.low-caloriediet.com/ 301 moved permanently over and over again. Is there something I'm looking for? My permalink structure is setup like this: https://www.low-caloriediet.com/%category%/%postname% – Tmac Aug 12 '14 at 15:01
  • When I opened `https://www.low-caloriediet.com/` I didn't get any redirection loop. Is this rule still active? – anubhava Aug 12 '14 at 15:30
  • No, I replaced it with my old one. Would you like me to put it back in quick? – Tmac Aug 12 '14 at 15:37
  • Yes pls put it back so that I can verify few things from `curl` – anubhava Aug 12 '14 at 15:38
  • I think you're htaccess code might be causing a redirect loop because not matter if you use https or http, it uses port 80 (I beleive). Not sure if its somethign to do with NGINX or a load balancer or what, but I have to use HTTP:X-Forwarded-Proto – Tmac Aug 12 '14 at 15:40
  • OK, its back. Thanks for your help! – Tmac Aug 12 '14 at 15:41
  • No https port is actually 443 not 80. Did you say it is Nginx not apache? – anubhava Aug 12 '14 at 15:41
  • Right, but I printed the port in my header and navigated to https and it displayed port 80... Yes, I beleive NGINX. I use bluehost for my host, and typically they use Apache, but they mentioned NGINX in our last conversation and using a site checker tool is said NGINX. – Tmac Aug 12 '14 at 15:46
  • Well, my site loads for me now! :) BUt, it did before for me. I just tried loading it in tools.pingdom.com but it said redirect loop. Maybe it will take a bit to propoagte – Tmac Aug 12 '14 at 15:49
  • It worked for me also few minutes back but again it showed looping error. Did something change? – anubhava Aug 12 '14 at 15:52
  • I didnt change anything after I dropped your updated code in the htaccess. The site wont load for you at all now? – Tmac Aug 12 '14 at 15:54
  • Unfortunately I don't know much about rewriting on Nginx. At present `curl` command is showing redirection loop. – anubhava Aug 12 '14 at 15:57