Better solution to prevent Wordpress ERR_TOO_MANY_REDIRECTS (only appearing at wp-admin)?

September 8, 2018 649 views
WordPress Ubuntu 16.04

Is there a way to prevent this error, ERRTOOMANY_REDIRECTS from appearing at /wp-admin after certain common installation conditions (described below). Here is what I did:

I pointed my DNS to Cloudflare.

Then on Cloudflare I created an A Record (@) pointing to my Digital Ocean droplet IP address, as well as a www CNAME Record aliased to that A (@) Record.

I set the SSL on Cloudflare to "Flexible" (and did not install SSL on my digital ocean droplet.)

I used the Wordpress One-Click installer to spin up a Wordpress site using the directions here:

https://www.digitalocean.com/community/tutorials/how-to-use-the-wordpress-one-click-install-on-digitalocean

Following the completion of the Wordpress install, I was getting ERRTOOMANY_REDIRECTS (but only when trying to log in at /wp-admin. The front of the site showed no errors).

In order to correct this error, I needed to change the WordPress Address (URL) and the Site Address (URL) at Settings - > General in the /wp-admin (backend) of the Wordpress site. However I couldn't login to the admin of the Wordpress site in order to do this, due to the ERRTOOMANY_REDIRECTS error.

I'm an FTP user, so I used FileZilla to add the settings below to the file wp-config.php which corrected the problem and allowed me to log in at /wp-admin (hooray!)

In FileZilla, I right-clicked on remote file, then clicked View/Edit (I did it this way, because I found that if I downloaded, edited, and then re-uploaded the file it changed the "owner" of the file which cause other problems.)

This opened the file in my text editor (I use Edit Pad Pro.)

Then I added the following to the end of the wp-config.php:

define('WP_HOME','http://www.your-site.com');
define('WP_SITEURL','http://www.your-site.com');

Using http not https

and

Making sure to use the www

I clicked Save in my local file editor, then went back over to FileZilla which then showed a prompt to Upload the file back to the server.

I clicked Yes, and checked to make sure the "Owner" of the file hadn't changed.

This worked for me.

4 Answers
vpsfix September 8, 2018
Accepted Answer

You could also add following code to wp-config.php to gain access to WordPress backend,

define('FORCE_SSL_ADMIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
       $_SERVER['HTTPS']='on';
edited by MattIPv4

Also I added the domain name in my Digital Ocean account and created an A (@) record pointing to the Wordpress droplet, as well as a www CNAME record aliasing that A (@) record.

Was that the correct thing to do?

After going through the steps above which restored access to the back end of my Wordpress site, I found the following:

I deleted the domain name entirely from my Digital Ocean account - it was causing excess redirects, and was not necessary. Only the Cloudflare DNS settings are necessary which point the domain (and the www version) to the IP address of the Wordpress droplet on Digital Ocean.

Then (again using FileZilla as above) I changed the URLs in wp-config.php to:

define('WP_HOME','http://your-site.com');
define('WP_SITEURL','http://your-site.com');

(removing the www from both of the URLs)

Everything now still works (including the admin login page at /wp-admin), and without the extra DNS re-directs.

Thank you @vpsfix ! Your fix tidied up everything, and https is now running the show.

So now my wp-config.php additions look like this:

define('FORCE_SSL_ADMIN', true);
if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')
       $_SERVER['HTTPS']='on';

define('WP_HOME','https://my-site.com');
define('WP_SITEURL','https://my-site.com');

Cheers!

Have another answer? Share your knowledge.