CodingWordPress

WordPress: how to change site URL

After installing and using WordPress, some references to the site address specified during the configuration (i.e.: www.example.com) are stored in the database.

If you need to change such address at a later time, you need to perform some steps to avoid references to the old address to persist in the DB.

Let’s see what to do, assuming that WordPress was initially configured for the address www.oldsite.com and that you are going to move it on www.newsite.com.

First thing to do is to perform a database backup, just in case you make mistakes during the procedure.

After we make sure we have such DB backup, we need to launch the following SQL queries on the database (obviously www.oldsite.com and www.newsite.com must be replaced with the addresses you chose):

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsite.com', 'http://www.newsite.com') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'http://www.oldsite.com','http://www.newsite.com');
UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldsite.com', 'http://www.newsite.com');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldsite.com','http://www.newsite.com');

If after these operations you are no longer able to access website on the new URL address, you probably made some mistake in the first of the four queries. In that case use WordPress relocate di functions, that can be enabled by inserting the following line at the end of the wp-config.php file:

define('RELOCATE', true);

Save the file and open the address http://www.newsite.com/wp-login.php, then type in your username ad password, click on Settings->General and make sure that both the lines “WordPress Address (URL)” and “Site Address (URL)” contain http://www.newsite.com as address.

Previous post

How to download Google Chrome offline installer

Next post

WordPress: how to change tables prefix

Fulvio Sicurezza

Fulvio Sicurezza

No Comment

Leave a reply

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