WordPress: Redirecting to wrong URL!!
Problem:
While trying to browse to http://www.example.com, it keeps redirecting to http://example.azurewebsites.net!!
Redirection Scenarios
There are a couple situations where one may face the WordPress Redirection issue:
- Migrated from another host
- Changed your custom domain name and it’s going to your old domain!
Understanding The Issue
This redirection can occur for two reasons:
- URL settings on the database. There are two fields named SITEURL and HOME within the wp_options table that control the URL redirects.
- Defined constants in wp-config.php
MySQL Workbench showing URL settings from wp_options table
Wp-config.php showing defined constants affecting URL Redirection. To update these URLs, follow (C).
Stopping The Redirection (and taking control of the site)
Not everyone is comfortable with making updates on a database so there are several _options given below. Here are a _few methods to fix this issue:
A) Recommended Method Through WordPress Admin
1. Login to WordPress Admin
2. Click on Settings -> General
- Find the WordPress Address (URL) and Site Address (URL) fields:
- Update it to your new URL as shown:
- Save Changes
B) If you no longer have access to WordPress admin, set the site in “Relocate” mode within wp-config.php
-
Edit wp-config.php
-
Before the comment line “That’s all, stop editing!”, insert a new line: define(‘RELOCATE’, true);
-
Save wp-config.php file
-
In your browser, open wp-login.php on your new site. Example: For the domain, http://www.mysite.com, the URL would be: http://www.mysite.com/wp-login.php
-
Login
-
Verify the address bar is correct
-
In WordPress Admin, go to Settings -> General
- Verify WordPress Address (URL) and Site Address (URL) are correct
-
Save changes
-
Go back to wp-config.php
-
Remove the define from step #2.
C) If you are unable to log into WordPress Admin, define new settings within wp-config.php
Note: This will hardcode the URLs and they will be disabled through the WordPress Admin -> Settings -> General Area. Because of this reason, it is not recommended.
define(‘WP_HOME’,’http://example.com’); define(‘WP_SITEURL’,’http://example.com’);
D) Manually update the HOME and SITEURL through a client like MySQL Workbench or PHPMyAdmin
Apply the following two queries to your WP_OPTIONS table:
__________________________________________________________________
UPDATE wp_options
SET option_value=’http://www.newaddress.com’
WHERE option_name = ‘home’
LIMIT 1;
__________________________________________________________________
UPDATE wp_options
SET option_value=’http://www.newaddress.com’
WHERE option_name = ‘siteurl’
LIMIT 1;
__________________________________________________________________
Reference: https://codex.wordpress.org/Changing_The_Site_URL