Fix WordPress login redirect loop when accessing wp-admin

There are several ways you can fix a redirect loop in WordPress. However, I was facing a redirect loop problem when trying to login to wp-admin. The solution #4 was the one that helped me log in to wp-admin without any ssl redirect loop.

1. Replace .htaccess content

Make a backup of your .htaccess by copying and pasting it under a different name or download it to your local machine.

Replace everything that’s in your .htaccess with the default WordPress:

# BEGIN WordPress

RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

More info here https://wordpress.org/support/article/htaccess/

If replacing your .htaccess content doesn’t work, do next:

2. Rename the plugins folder

Find your plugins folder (usually inside ./wp-content/) and rename it to anything like .plugins then check the site.

If there’s no redirect loop, you have to identify which plugin is causing the redirect loop. Rename each plugin folder one-by-one (using either FTP, cPanel file manager or any other file manager) until you find the one that’s causing the redirect loop. Some people found that Yoast SEO was generating a redirect loop.

If you still have a redirect loop after renaming your plugins folder, do next:

3. Rename the themes folder

Find your themes folder (usually inside ./wp-content/) and rename it to anything else. You could append an underscore like this: themes_

If you managed to fix that by renaming the themes folder you have to identify which theme is causing the redirect loop and the find the file.

If renaming your themes folder doesn’t solve your redirect loop, do next:

4. Edit your wp-config.php

Open your wp-config.php file and add the code below:

define('FORCE_SSL_ADMIN', true);

if( strpos($_SERVER['HTTP_X_FORWARDED_PROTO'], 'https') !== false )
   $_SERVER['HTTPS'] = 'on';
else
   $_SERVER['HTTPS'] = 'off';

I found that piece of code on https://wordpress.org/support/topic/to-many-redirect-on-wp-admin/

This code helped me fix my site running on easyengine nginx where there’s no .htaccess file to modify.

If that doesn’t work, try the next one:

5. Cloudflare SSL full mode

If your site is on cloudflare, one way to fix the ssl redirect loop is to switch your SSL to Full or even Full (strict).

Cloudflare SSL full mode for ssl redirect loop fix solution

More info on that here https://developers.cloudflare.com/ssl/origin-configuration/ssl-modes/full/

6. Not recommended. Edit your template-loader.php

Open the file template-loader.php that you can find inside ./wp-includes/ folder and comment out line 13:

// do_action( 'template_redirect' );

If that works, you have to contact someone to debug your website.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *