Fixing Wordpress Redirect Issues

Last updated: July 19th 2022

Introduction

Wordpress really wants to redirect visitors to whatever address is set in Wordpress settings. Also, some plugins may save the entire website URL of your site for links (some menu plugins do this for example)

This can result in infinite redirect loops where you get a browser error along the lines of "Too many redirects"

Another problem you may encounter is that your Wordpress site is redirecting you to an old website address. This article outlines various ways of fixing these issues.

Let Wordpress know what the correct Site URL is

If you are changing your Wordpress website address, i.e. your domain name - you need to let Wordpress know what its new website address is. This typically fixes the redirect loop problem.

This only applies if the domain name of your website has changed. If you haven't changed your website address and are seeing redirect issues, the problem is most likely at the DNS level. Scroll down to the DNS section in this article for possible solutions.

In order to update your Wordpress site url, Webdock has a tool called wp-cli which can help you with this task quite easily. 

The benefit of using WP-CLI is that you make sure that all plugins which may reference your old website address get updated as well as the Wordpress core

Installing WP-CLI

WP-CLI is a tool which helps you (and the Webdock backend) interact with your Wordpress installation,

If your website is on a Webdock server this is really easy: You start by going to Manage Wordpress and simply click the button to deploy WP-CLI to your server.

If you installed Wordpress using Webdock, then you have already done this in the initial setup of Wordpress.

If you have just migrated your Wordpress site to Webdock, once WP-CLI has been installed, you would then just click on the “Save path” button below the Wordpress is already installed section.

If you need to manually install WP-CLI - take a look here:

Installing WP-CLI (official guide)

Updating the Site URL

Although these WP-CLI commands should be safe to run, please create a database backup or perform a snapshot in Webdock in case something goes wrong. 

Once WP-CLI is installed, you can simply run the following command on the command line, and you should be good to go (change your working directory to your web root first, this is typically /var/www/html):

# cd /var/www/html
# sudo wp search-replace 'example.dev' 'example.com' --skip-columns=guid

Where example.dev is your old domain and example.com is your new one. This will also fix any plugins or other components which may have written absolute URL’s to the database.

In some cases you may need to include the http:// part if you are switching from a non-ssl enabled website to Webdock, which is always SSL enabled, then the command would become:

# sudo wp search-replace 'http://example.dev' 'https://example.com' --skip-columns=guid

Updating the Site URL without using WP-CLI

We recommend using wp-cli as then you can be sure that all references to your old website address are updated in a safe manner. However, you can also try to just tell the Wordpress core what the new website URL is. This will work for sites that do not use plugins that reference the site url in their own data / settings and may work fine for you. You can update the site url in the Wordpress dashboard settings (if you have access) or in the wp-config file, or directly in your database by hand (although this may result in errors if you are modifying certain tables)

More information on various other ways to update site URL’s can be found here:

https://wordpress.org/support/article/changing-the-site-url/#changing-the-site-url

Wordpress redirects colliding with DNS settings

As Wordpress likes to redirect to the website address set in its settings, this can conflict with other things such as redirects on the DNS level.

Say that you for example have set in your DNS that the domain should always redirect from example.com to www.example.com

If you then have set the domain in Wordpress settings to just example.com - then Wordpress will always try to redirect www to non-www and the DNS level will be trying to do the reverse. You will then get a “Too many redirects” message in your browser. Fix this by aligning the two settings so that there is no conflict anymore.

If using Cloudflare Caching and / or SSL and still seeing issues: Check your settings

Cloudflare may want to do redirects or may be the indirect cause of redirects on your server. For example if you have Cloudflare caching turned on and Cloudflare SSL setting set to Flexible you will probably see infinite redirects on your website.

This is because Cloudflare tries to connect to your server without SSL and if your server is set up to always redirect to https (SSL) then this will also result in redirect errors. 

The first thing you should try / make sure of is that your SSL setting in Cloudflare is set to Full. If that doesn't work, try disabling all Cloudflare cache and SSL. 

Then see if you can connect to your site - if you can now connect, and everything looks fine. try turning on Cloudflare again making sure that the SSL setting is set to Full.

In short: Try disabling all Cloudflare features on your A and AAAA records and make sure everything looks good / works before turning on Cloudflare again, making sure SSL is set to Full

Browsers may trip you up by caching redirects

Google Chrome especially is quite aggressive in caching redirects. If you think you have solved the issue by follwoing the steps here, try checking in another browser as what may be happening is simply that the browser you have been using thus far is "remembering" the old redirect which was happening.

If all else fails - contact us and we will help

If nothing works and you are cursing Wordpress to the deepest parts of hell - don't despair! Write us a note and a friendly Webdock supporter will take a look and diagnose what's going on and maybe even fix it for you :)

We use cookies. Please see our Privacy Policy.