Problem: By mistake user “Changed the WordPress address URL” in General Settings and now user cannot login nor access the admin page. User may not even access the database, but still user can access the login page i.e. site-name/wp-login.php
Solution: We can fix “Too many redirect issue” in various way without touch Database or without logging in to the website.
Before providing solutions, let me tell you how this problem occurs. Too many redirect issue is very common in WordPress and if you Google with these keywords, you will get hundreds of such posts on it. Well, main cause for this is misconfigured value or your WordPress URL as shown in below image:
Let’s assume your WordPress URL is www.site-name.com/wp/ and by mistake you wrote anything else but not this like www.site-name.com/
So, It will always be trapped in a loop to redirect your site from site-name.com/wp to site-name.com and so on…
In Firefox you will see error like this (The page isn’t redirecting properly):
And in Chrome error will be like this (This webpage has a redirect loop):
Solutions To Redirect loop in WordPress
1. Fixing the “Too Many Redirect issue” by adding 2 lines in wp-login.php (usually it will be at wordpress_site/wp-login.php )Â which will be used to reset the address:
//FIXME: do comment/remove these hack lines. (once the database is updated)
update_option(‘siteurl’, ‘http://your.domain.name/the/path’ );
update_option(‘home’, ‘http://your.domain.name/the/path’ );
Note: Once it is fixed, just remove these two lines from the file
2. Fixing the issue using wp-config.php (which does not need phpMyAdmin). đŸ™‚
It is possible to set the site URL manually in the wp-config.php file.
Add these two lines to your wp-config.php, where “example.com” is the correct location of your site. (Where WordPress is installed)
define(‘WP_HOME’,’http://example.com’);
define(‘WP_SITEURL’,’http://example.com’);
Note: This is not necessarily the best fix, it’s just hard coding the values into the site itself. So, You won’t be able to edit them in the General settings page any more when you are using this method to fix this issue. Once it is fixed just remove these two lines from the file.
3. Using Database through PHPMyAdmin
UPDATE wp_options SET option_value = 'http://your-site.com' WHERE option_name IN ('home', 'siteurl');
Hope this will help someone as it helped me and many of our clients.
Image Source: www.wpbeginner.com