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

Richard Chambers
Published: 6 September 2022Last updated: 24 August 2023
Share:

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

The `too many redirects` error in a browser

What is the ERR_TOO_MANY_REDIRECTS?

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, ERR_TOO_MANY_REDIRECTS are caused by incorrect or poorly-defined redirect rules in your .htaccess file, or a plugin forcing a redirect over and over. 

Common causes of ERR_TOO_MANY_REDIRECTS

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.

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.

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 which causes the ERR_TOO_MANY_REDIRECTS.

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.

Force HTTPS Scripts

Some Content Management Systems (CMS) such as Joomla have options that can force HTTPS connections to your site as a part of the integration. Enabling these makes tweaks to the code to enforce this – however, if you’ve already included your own scripts to force HTTPS or are using 20i’s option to do so in the SSL/TLS area, then this could potentially conflict and lead to a loop.

Check your current CMS setup to see if any options to force HTTPS connections are enabled. If they are, disable or remove any other scripts or options that will be enforcing this to remove any conflicts.

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.