The estimated reading time for this post is 76 seconds

So you just got a shiny new domain or you want to change your long hard-to-remember domain to a short one? If you don’t change some database values accordingly, you will be greeted with a blank PHP error screen when you come back.

Instead of editing the database, here’s a easier way to change the URL.

Step 1

1. In wp-config.php, add this on top:

define('RELOCATE',true);

2. Go to [Your Site]/wp-login.php and WP will update the website address for you.
3. Login into the admin, go in Generals settings and edit the settings accordingly.

If you prefer the longer, geekier database way, here’s how:

1. Login to phpMyAdmin or your SQL manager

2. In the table wp_options, edit siteurl and home

3. Change the values to your new website URL.

Step 2

Now you need to update permalinks, image and links within your posts. Images in your posts are still using your old URL, since WordPress uses absolute and not relative URLs. Images won’t display properly otherwise.

  1. You need to login to your database manager like phpMyAdmin.
  2. Go in your WordPress Database
  3. Click SQL and execute the following
UPDATE wp_posts /*Updates permalinks*/
  SET guid
      = REPLACE(guid, 'http://Old URL', 'http://New URL');
UPDATE wp_posts /*Updates Images and Media*/
  SET post_content
      = REPLACE(post_content, 'http://Old URL', 'http://New URL');
UPDATE wp_comments /*Update Trackbacks*/
SET comment_author_url
    = REPLACE(comment_author_url, 'http://Old URL', 'http://New URL')
WHERE comment_type <> "";

Thanks to Dave Miller!

You might also like: