Changing Your WordPress Site URL

Posted on Jul 3, 2011 in WordPress | 0 comments

When you move your WordPress site, letting the site know about its new URL can be a hassle, but can lead to many types of errors if you are not careful: the site may not load at all, only the home page may load, images may not load properly, internal links may be broken, and so on. Here is a checklist for the next time you have to do this.

There are two main ways to do this; one requires access to run SQL queries (usually by using the PHPMyAdmin tool in your web host’s dashboard, which is typically CPanel), and the other requires editing files through FTP and using a plugin.

 

 

No matter which method you use, make sure afterwards to login to WordPress, go to Settings > Permalinks and click the “save” button to force the permalinks to refresh. If you do not do this, permalinks will not work properly, meaning you will get an error if you try to access anything other than the home page.

How to Change Your Site URL With SQL Queries

Copy the following into the “SQL” tab of PHPMyAdmin. Make sure to change the URLs in each query to reflect the correct old and new URL. I prefer to first copy it into Notepad, then use the find and replace tool to accomplish this.

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com') WHERE option_name = 'home' OR option_name = 'siteurl';


UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://www.oldsiteurl.com', 'http://www.newsiteurl.com');


UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, 'http://www.oldsiteurl.com','http://www.newsiteurl.com');

These queries come from the excellent article, 13 Useful WordPress SQL Queries You Wish You Knew Earlier. However, beware of the query in the article to change GUIDs in your database. The WordPress Codex explicitly warns to “never, ever” change GUIDs in the database.

Note that this may not change every reference in the database. At the very least, you should use the PHPMyAdmin “search” tab to see if anything else in the wp_options table uses the old URL. Some you may be able to change directly; others are best changed through WordPress. If the setting has to do with a particular plugin, deactivating and reactivating the plugin may correct it, or you may be able to manually update the setting through the plugin settings in WordPress. Don’t change what you don’t understand.

Don’t forget to refresh your permalinks!

Updating Your URLs with a Plugin

The Velvet Blues Update URLs plugin is a wonderful tool to update your site URL. However, you won’t be able to login to WordPress until two key URLs have been changed.

The WordPress Codex describes multiple ways to change your “site URL” and “home” values without direct SQL access. If you follow these methods, I find Filezilla to be quite useful, since you can right-click a file, choose to edit it, make your changes, save it and have it automatically go back to the server. This saves you several steps.

After you do that, you should be able to access your site and install the Velvet Blues Update URLs plugin. Once the plugin is installed, to go Settings > Update URLs. The plugin has a simple interface: just select that you want to update permalinks, then specify the full old and new URLs (including the http://) and then away you go!

The problem with Velvet Blues is that it updates all references… including GUIDs, which the WordPress Codex warns against. However, sometimes you have to do what you have to do.

0 Comments

Trackbacks/Pingbacks

  1. Moving Your WordPress Site | Alamoxie - [...] or from oldsitename.com to newsitename.com—then you will have additional steps. See Changing Your WordPress Site URL. Looking for more…

Submit a Comment

Manage your comment subscriptions