Wordpress login page be Redirect loop

The top page and wordpress login page get a redirect loop and an error occurs.
Other pages can be displayed without any problem.

In Google Chrome,
If you check in verification mode ⇒ network ⇒ preserve_log

Many 302 Status are displayed.

Please tell me the solution.

Basically the requests are bouncing between HTTP and HTTPS. If you put the following two lines of code into your wp-config.php file then it will likely fix the issue:

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

The first line ensures that SSL (HTTPS) is used on the login / admin pages.
The second line ensures that WordPress responds with HTTPS in the links that it generates, rather than just HTTP.

1 Like

This is bad advice and keeps the site insecure. The OP seemingly only needs to fix his Cloudflare configuration and choose the proper encryption mode, Full Strict.

1 Like

The code comes straight from WordPress: Administration Over SSL – WordPress.org Forums

Doesn’t matter if you have SSL Strict enabled, this problem is behind the reverse proxy.

1 Like

That link specifically refers to an insecure configuration with is neither the case here nor a good idea.

The OP simply needs to ensure his site is properly configured for SSL and works fine. In that case it will work on Cloudflare as well, regardless of proxy or not.

1 Like

The most common reason for a redirect loop is a bounce between HTTP and HTTPS, and that’s because the reverse proxy terminated the HTTPS connection. WordPress therefore receives an HTTP request and maybe the HTTP_X_FORWARDED_PROTO header.

Unless you factor that into your WordPress config like in my original answer, you’re going to have redirect loops. WordPress is going to respond in HTTP, because the reverse proxy sent the request in HTTP. Totally normal situation and not at all unique to WordPress.

The OP simply needs to ensure his site is properly configured for SSL and works fine.

Yeah, see my original suggestion. Your comment basically says “fix the bug by not having bugs”. It’s not helpful at all.

1 Like

The most common reason for a loop on Cloudflare is an incorrect encryption mode and hence the suggestion to double check that is set to the correct mode Full Strict.

This has been discussed endlessly, so please use the search for further details.

1 Like

What should I do specifically?

What’s your encryption mode on Cloudflare? Make sure that’s Full Strict.

I don’t know “encryption mode on Cloudflare”

What does it say at https://dash.cloudflare.com/?to=/:account/:zone/ssl-tls?

1 Like

This is the last line of wp-config.php.
Should I add it at the end of here?

===========
/ ** Absolute path to the WordPress directory. * /
if (! defined (‘ABSPATH’)) {
define (‘ABSPATH’, DIR.‘/’);
}
/ ** Sets up WordPress vars and included files. * /
require_once ABSPATH.‘wp-settings.php’;

↓ ↓ ↓ ↓

===========
/ ** Absolute path to the WordPress directory. * /
if (! defined (‘ABSPATH’)) {
define (‘ABSPATH’, DIR.‘/’);
}
/ ** Sets up WordPress vars and included files. * /
require_once ABSPATH.‘wp-settings.php’;

define (‘FORCE_SSL_ADMIN’, true);
$ _SERVER [‘HTTPS’] =‘on’;

Don’t do that, you should not tinker with your site setup, leave these things alone.

1 Like

First, Sandro has a great post about the “Full Strict” SSL mode that they’re suggesting, so try that first: Why you should choose Full Strict, and only Full Strict

Second, ensure that all your website pages continue to work after changing that setting. If they do, great! If not, then you might want to look into using Cloudflare Origin Certificates to ensure the connection between Cloudflare and your server is encrypted.

Third, check whether your redirect loop has been solved. If not, try my original suggestion by editing your wp-config.php and adding those two lines of code.

Fourth, check if your redirect loop has been fixed. If not, remove those lines and let us know,

1 Like


Is this OK?

No, it isn’t. As I already mentioned, change that to Full Strict.

1 Like

Okey,Thank you, boss

Have you changed it?

1 Like

Okey,Thank you, boss,I will try.

I have done.