Welcome to 20i Support

Web Hosting Knowledge Base

Why am I getting a ‘Too Many Redirects’ error?

'Too Many Redirects' errors are caused by sites stuck in a loop of redirects.

The 'too many redirects' error in a browser

One or multiple redirections point to themselves, resulting in the site being unable to load as it will continuously redirect until either the browser stops it early or the site goes down.

Most commonly, these are caused by incorrect or poorly-defined redirect rules in your .htaccess file, or a plugin forcing a redirect over and over. Below are some common causes  - 'always true' rules, mixed content and caching.

We'll explain what they mean and show you how to fix them.

1. Always true rules

Redirect rules set in the .htaccess file have conditions. These conditions decide when a redirect rule should redirect a site, so that the site doesn’t always redirect. If these conditions aren’t set correctly however, they can always be ‘true’, meaning that the redirect will always occur and as a result the site will loop.

For example, we have a site domain.com and we try to redirect this to our subdomain my.domain.com

One way we could do this is via the following:

RewriteCond “%{HTTP_HOST}” “domain.com$”

RewriteCond “%{REQUEST_URI}” “^/”

RewriteRule “.*” “https://my.domain.com/” [L,R=301]

In the above example, we have our condition:

RewriteCond “%{HTTP_HOST}” “domain.com$”

Which states that, if the URL contains ‘domain.com’, redirect the site. However, this will lead to a loop, as our subdomain also contains ‘domain.com’, resulting in the too many redirects error.

A much better way to do this redirect would be instead to use:

RewriteCond %{HTTP_HOST} !^my\.domain\.com [NC]

RewriteRule ^(.*)$ http://my\.domain\.com/$1 [R=301,L]

Which instead uses the condition:

RewriteCond %{HTTP_HOST} !^my\.domain\.com [NC]

This checks to see if the URL is not the subdomain, and redirects the site if it’s not.

It’s worth looking through your rules and making sure this type of logical loop doesn’t occur.

If you’re unsure, try renaming your .htaccess file. If the error stops when doing so, something in that file is causing the loop itself.

 

2. Mixed Content

The term ‘Mixed Content’ refers to when parts of a website on HTTPS try to load content over HTTP. In more uncommon cases, this can result in a site correcting itself to HTTP, then redirecting to HTTPS, resulting in a loop between the two.

In cases such as this, it’s best to temporarily remove any rules that may be enforcing HTTPS, and then updating all of your site’s URLs to ensure they’re either all on HTTP or all on HTTPS.

We have a full guide on finding and fixing mixed content here.

 

3. Caching

Caching can also cause a redirect loop as site and server caching can store redirects, resulting in a rule that has been removed to continue to be used.

The quickest way to check to see if this is the case is to visit the site with a query string at the end, for example:

https://mydomain.com/?nocache

Anything after the '?' is ignored, so you can write anything. Doing so will bypass the cache on the site and force the site to load directly.

If the site then loads fine without the redirect error, you can confirm that caching is what's causing the redirect.

Check your site for any cache folders and clear them, and then clear the edge cache from within your package:

  • Log into My20i and head to your Manage Hosting area
  • Select Options > Manage on the hosting package you’d wish to edit
  • Select Edge Caching from under the CDN section of the package

Edge caching in the My20i 'Manage Hosting' menu

At the bottom of the Edge Caching page, select Purge Everything. The server cache will be cleared within a few minutes.

Now you should be free of the 'too many redirects' error. Get in touch with our support team if you need further help.