How to change your WordPress Domain

By Fábio Zaffani How ToWordpress at 28 de January de 2012

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, ‘http://www.old-domain.com’, ‘http://www.new-domain.com’) 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, ‘http://www.old-domain.com’, ‘http://www.new-domain.com’);
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.

3 thoughts on “How to change your WordPress Domain

  1. 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 ‘://old-domain.com’, ‘://new-domain.com’)’ at line 1

    Reply April 09 at 8:54
  2. I had replaced my old-domain.com and new-domain.com with my genuine domain names

    Reply April 09 at 8:55
    • Check the text, to see if only the domain was changed, any type of char added/removed can cause this type of SQL error

      Reply April 17 at 18:25

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>