WordPress: Redirecting to wrong URL!!


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:

  1. URL settings on the database. There are two fields named SITEURL and HOME within the wp_options table that control the URL redirects.
  2. Defined constants in wp-config.php

2016-07-12 16_47_49-Start

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

01 - General

3) Find the WordPress Address (URL) and Site Address (URL) fields:

03 - Update URL

4) Update it to your new URL as shown:

04 - Updated URL

5) Save Changes

05 - Save Changes

B) If you no longer have access to WordPress admin, set the site in "Relocate" mode within wp-config.php

1) Edit wp-config.php

2) Before the comment line "That's all, stop editing!", insert a new line: define('RELOCATE', true);

2016-07-13 11_20_57-Diagnostic Console - Internet Explorer

3) Save wp-config.php file

4) 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

5) Login

6) Verify the address bar is correct

7) In WordPress Admin, go to Settings -> General

01 - General

8) Verify WordPress Address (URL) and Site Address (URL) are correct

04 - Updated URL

9) Save changes

10) Go back to wp-config.php

11) 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.



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'



UPDATE wp_options

SET option_value='http://www.newaddress.com'

WHERE option_name = 'siteurl'



Reference: https://codex.wordpress.org/Changing_The_Site_URL