How to change your WordPress Domain

This is a problem that many users face sometimes, moving wordpress domains is not an easy task because you have many things to consider, if you just move your files and don’t change the correct configurations in the database you will break everything on your site, another common problem is that after you migrate to the new server your internal links (the ones created in the posts) may also be pointing to the old domain.

Now imagine if you have hundreds of posts to change? Would be to cost, time-wise, to go through all those posts changing link by link, also there are some options related to the domains and links that are created once WordPress is installed and there is no easy way to change it trough the admin.

The solution that address both of this problems is through some easy SQL querys that will do all the hard work for you:

First you need to set the new domain on your wp_option database

UPDATE wp_options SET option_value = replace(option_value, ‘’, ‘’) WHERE option_name = ‘home’ OR option_name = ‘siteurl’;

Finally, lets check through the post content and update the link

UPDATE wp_posts SET post_content = replace(post_content, ‘’, ‘’);
If you look for the database after those changes you might find some remaining text pointing to the old domain, but normally those files are transient (cache) files so you don’t have much to worry about.

That’s pretty much all you need to, for any questions or help feel free to leave a comment bellow.


4 Comentários. Comentar

9 de abril de 2012 8:54

Not Working…!!!

Gives Error

#1064 – You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘://’, ‘://’)’ at line 1

9 de abril de 2012 8:55

I had replaced my and with my genuine domain names

Fábio Zaffani
17 de abril de 2012 18:25

Check the text, to see if only the domain was changed, any type of char added/removed can cause this type of SQL error

Thambapanne Net
30 de maio de 2012 15:20

Not Working…!