HTTP to HTTPS 301 Redirect Error

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:

Read More

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

Related posts

Leave a Reply

2 comments

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

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