This is How to Fix the "Too Many Redirects" Error After Switching to HTTPS
Making the switch from HTTP to HTTPS is an important step for any website, but it can sometimes lead to unexpected issues. One of the more common problems is encountering a "too many redirects" error, where your site gets stuck in an endless loop of redirects between the HTTP and HTTPS versions.
This redirect loop happens because your WordPress site and web server aren't properly configured to handle the HTTPS protocol. As a result, your site thinks it's still on the HTTP version and keeps trying to redirect to the HTTPS version, which then redirects back, and so on.
In this article, we'll walk through the most common causes of the "too many redirects" error after switching to HTTPS, and show you how to properly configure your WordPress site and web server to eliminate the redirect loop.
What Causes the "Too Many Redirects" Error?
There are a few main reasons why you might run into the "too many redirects" error after moving your WordPress site to HTTPS:
1. Incorrect Proxy Header Configuration
If you're using a reverse proxy or load balancer in front of your WordPress site, it needs to be properly configured to pass along the correct scheme (HTTP or HTTPS) in the X-Forwarded-Proto
header. If this header isn't set correctly, WordPress will think the site is still being accessed via HTTP, and will try to redirect to the HTTPS version, leading to a redirect loop.
2. Incorrect WordPress Site URL Configuration
Your WordPress site has two key URL settings – the "WordPress Address (URL)" and the "Site Address (URL)". These need to be updated to the correct HTTPS URL, or else WordPress will think the site is still on HTTP and try to redirect.
3. Missing HTTPS Configuration in WordPress
Even if you've updated your WordPress site URLs, you may still need to make additional changes in your wp-config.php
file to ensure WordPress properly detects the HTTPS protocol.
4. Caching Issues
If you have caching plugins or a caching service (like a CDN) in front of your WordPress site, outdated cached pages could also contribute to the redirect loop.
Let's go through how to diagnose and fix each of these potential causes.
Fix Proxy Header Configuration Issues
If you're using a reverse proxy or load balancer in front of your WordPress site, the first thing to check is the X-Forwarded-Proto
header configuration.
This header is used to indicate whether the original request came in over HTTP or HTTPS. WordPress and other server-side software use this header to determine the correct protocol to use for redirects and other functionality.
If the X-Forwarded-Proto
header isn't set correctly, WordPress will think the site is still being accessed via HTTP, even though the user is actually on the HTTPS version. This will trigger the redirect loop.
The fix is to ensure your reverse proxy or load balancer is properly configured to set the X-Forwarded-Proto
header to the correct value.
For example, in Nginx you would add the following line to your server configuration:
proxy_set_header X-Forwarded-Proto $scheme;
This tells Nginx to set the X-Forwarded-Proto
header to the current scheme (HTTP or HTTPS) of the incoming request.
In Apache, you would use the following directive in your virtual host configuration:
RequestHeader set X-Forwarded-Proto $scheme
Make sure to restart your web server after making this change for it to take effect.
Update WordPress Site URLs
The next step is to ensure your WordPress site URLs are properly configured for HTTPS.
WordPress has two key URL settings that need to be updated:
- WordPress Address (URL): This is the location of the main WordPress files.
- Site Address (URL): This is the URL that visitors use to access your site.
Both of these settings need to be updated to the correct HTTPS URL. You can do this by going to the WordPress admin dashboard, navigating to Settings > General, and updating the URLs.
Once you've updated these settings, WordPress will start using the correct HTTPS URLs for internal links, redirects, and other functionality.
Configure WordPress for HTTPS
Even after updating your WordPress site URLs, you may still need to make some additional changes to ensure WordPress properly detects the HTTPS protocol.
The most common fix is to add the following code snippet to your wp-config.php
file, right above the require_once
line:
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
$_SERVER['HTTPS'] = 'on';
This code checks the X-Forwarded-Proto
header and sets the $_SERVER['HTTPS']
variable accordingly. This helps ensure WordPress correctly identifies the HTTPS protocol, even if your web server isn't directly setting the HTTPS
server variable.
You can also try adding the following line to your wp-config.php
file:
define('FORCE_SSL_ADMIN', true);
This will force the WordPress admin area to only be accessible via HTTPS, which can help resolve any lingering redirect issues.
Clear Caching and Test
If you're still experiencing the "too many redirects" error after making the above changes, the final step is to clear any caching that may be causing the issue.
Cached HTTP pages can trigger the redirect loop, so you'll want to clear the cache on any caching plugins, CDNs, or other caching services you have in place.
Once you've cleared the cache, test your site thoroughly to ensure the redirect loop has been resolved. Try accessing your site via both the HTTP and HTTPS versions, as well as through various entry points, to verify the issue has been fixed.
Get a Free AI Website Audit
Automatically identify UX and content issues affecting your conversion rates with Flowpoint's comprehensive AI-driven website audit.
Conclusion
The "too many redirects" error is a common issue when moving a WordPress site from HTTP to HTTPS, but it's usually fairly straightforward to fix.
The key is ensuring your web server is properly configured to pass along the correct protocol information, your WordPress site URLs are updated, and WordPress itself is properly detecting the HTTPS protocol. With a few targeted configuration changes, you can eliminate the redirect loop and get your site running smoothly on HTTPS.
If you're still experiencing issues after trying these steps, Flowpoint.ai can help identify any remaining technical problems impacting your site's performance and conversion rates, and provide tailored recommendations to fix them