WordPress: Change URL

When deploying a site (and database) from development to production, when going to the production the site goes back to development.

That’s because in WordPress, site URL is defined and saved in database by default.

According to the official document, there are several ways to change URL.

Method 1: update database

URL information are installed in <prefix>_options table. Locate option_names ‘siteurl’ and ‘home’ and update option_value to the new URL.

Or run this SQL after copying the database to production:

update <prefix>_options
set option_value = 'http://yoursite.com'
where option_name = 'site_url' or option_name = 'home'

Method 2: update config file – relocation

Edit wp-config.php and add the following code after all the define statements:

define('RELOCATE',true);

Login to the new site after the above change.

Important: this line must be removed after login.

You will need to go to setting to update the site url in General Settings.

Method 3: update config file – add url information

Edit wp-config.php and add the following code:

define('WP_HOME','http://yoursite.com');
define('WP_SITEURL','http://yoursite.com');

The URL information saved in the database will be ignored.

Note that the urls also can’t be changed via General Settings.

Important: update internal links

In WordPress, absolute path is used for internal links. You you need to globally update all internal links to the new URL as well.

1 thought on “WordPress: Change URL

  1. Nancy Reply

    Much appreciated for the information and share!
    Nancy

Leave a Reply

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