Oct 1, 2007
My Digital Life Editorial Team

How to Move WordPress Blog to New Domain or Location

For blogger who self-hosts the WordPress blog publishing system on a web hosting server with own registered domain name, sometimes, you may decide to reorganize the blog link URL to make it tidier or to reflect new focus or theme of the blog. If you decide to change the URL or link location of your WordPress blog due to changing of domain name (such as from http://www.old-domain.com/ to http://www.new-domain.com/) or the blog to another directory location (such as from http://www.domain.com/ to http://www.domain.com/blog/), there are some steps that should be done to ensure the proper migration and no breaking links.

The tricky part when moving WordPress blog to another location is that WordPress is using absolute path in URL link instead of relative path in URL link location when stores some parameters in database. Within blog posts’ contents itself, users may also use the old URLs when creating reference backlinks. All these values in the database will need to be changed when WordPress is moved. The following guide will show you which database fields that has references or values related to blog’s URLs that you want to modify. Note that this guide is not about how to move WordPress blog from one server or host to another new hosting service.

Once the blog has been moved (all files copy over in case of moving location or server or new domain name properly propagated across Internet for new domain name), the first thing to change is to tell WordPress the new blog location (wp-config.php should be no changes, and .htaccess file should be also no changes. If for some reason mod_rewrite rules for friendly URLs no longer works, you can always regenerate the .htaccess file via WP Administration’s Update Permalinks page). This value can be changed via WordPress Options page, but if you no longer able to access to old blog URL, you have to modify the value via MySQL database.

Note: The guide uses SQL statements based on MySQL replace() function to modify the database. To run SQL queries, login to MySQL database that houses WordPress tables via phpMyAdmin or login to the DB server and run MySQL client as root.

To update WordPress options with the new blog location, use the following SQL command:

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';

After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as absolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:

UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');

If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');

Browse through WordPress blog to check if everything is okay. You also need to re-login to WP Administration as authentication cookie has now became invalid due to different domain.

295 Comments

  • Just used your tutorial and it worked great! Thank you very much!

  • [...] moving wordpress site [...]

  • [...] Mover un blog en WordPress a otro dominio: “How to Move WordPress Blog to New Domain or Location“ [...]

  • [...] case of need, THIS can really helps ! This entry was written by Christophe, posted on September 11, 2008 at 10:34 [...]

  • [...] バイトで必要になったので調べた。How to Move WordPress Blog to New Domain or Location » My Digital Lifeというエントリが参考になる。 [...]

  • You just save my life! lol!

    Thanks for your article.

    It worked great! No fuzz!

  • [...] database across, and after a few little changes here and there (wordpress plugins and a few little database changes) all was [...]

  • [...] Once you have uploaded the posts to the new blog, you’ll also want to consider running the following 2 queries as suggested here: [...]

  • great info :)

  • [...] SQL codes from mydigitallife.info SHARETHIS.addEntry({ title: “How to move WordPress blog from old domain to new domain with 301 [...]

  • YOU TOTALLY SAVE MY LIFE!!!!!!!! THANK YOU SO SO SO VERY MUCH! Yea!

  • Gold information.

    You saved me hours.

    Cheers

  • Hi folks,

    I had the same probs, butt I never knew on what it depend's.

    I changed the sites Url in the admin area of my WordPress-blog, but that was an fault.

    So nothing would be shown on the right place.

    Therefor I needed to change it back, but there is no way to get in the admin area again logically, after I've changed the root Url.

    So I opened my mind to get a solution. And just in this Moment it comes over me:

    …only go on your hosting surface and start PHPmyADMIN and find the following database entry:

    "Your WP-Blog database"–>wp_options–>make this database Entry editable–>now find the row "site_url"–>and change in the "options_value"column the root of your blog–>safe it and it's done!

    greetings, Simon

  • [...] I’ve posted this comment to the mydigitallife.info [...]

  • yes there are open
    http://www.demonoid.com/

  • Thanks for that. When I googled for this topic another blog said , to this you have to backup the entire database, create new db and upload again. I was really tensed, but this was actually completed in seconds…..:)

  • [...] the first thing to be done was to get hold of all the old posts (though very less in number). Here google served as a saviour and I got hold of a plugin called ‘wp-migrate‘, which let me export all the posts along [...]

  • Thanks a lot for this tutorial! I've been wanting to do this for months but never dared because I was afraid of losing all my hard work. You really saved my day.

  • Thanks so much for this post. It was tremendous help. That was so easy to follow and worked perfect.

  • [...] all their sites to the new site. Some of these sites were wordpress powered. Thankfully, I found this article that made the move a [...]

  • Thanks for this!

    Everything working. Thanks for providing this valuable resource. Was invaluable for helping move our prototype WordPress installation from my home server to full on hosting!

  • I had no problem running the first query – the site found the home page instead of displaying a 404 error.

    But whilst the second query executes (I am told 2 rows are affected) and when I click a link in the new domain site the correct url is shown in the address bar, all I get is a 404 Not found message saying the requested URL is not on the server – what does this suggest, have I lost some files?

  • I just executed this command through PHPMyAdmin after dealing with 2 days of phantom redirects… turns out all that was wrong is I forgot to change the URL. This solved ALL my problems. You have no idea what a godsend this blog was to me. THANK YOU!

  • hi @ all i need plug in for hosting for wp who can help me

  • [...] url (siteurl) didn’t seem to help. More grumbling and puzzling around until I came across this post describing how which database values needed changing. Taking the advice of one of the comments this [...]

  • [...] cambiar el de dominio o servidor a su blog en WordPress estos son los tutoriales que utilicé: How to Move WordPress Blog to New Domain or Location y Changing The Site [...]

  • An easier way to replace all occurrences of your old domain name is to export your database into a text file using phpmyadmin or a backup plugin, then use a text-code editor to find and replace all occurrences of olddomain.com with newdomain.com.

    Import and voila!

  • [...] Read full article on this link http://www.mydigitallife.info/2007/10/01/how-to-move-wordpress-blog-to-new-domain-or-location/ Tags: wordpress This entry was posted on Wednesday, May 21st, 2008 at 1:30 am and is filed [...]

  • thanks for sharing this howto

  • they had the wild playing still there. work visit little done it. let it go. reminded damage the forests

  • [...] 1- Backup des données sur le serveur web 2- Backup de la base de données de l’ancien domaine (design.2803) 3- Création du dossier blogdecodesign.fr sur le serveur et de blogdecodesign.com avec une redirection 301 en htaccess vers le .fr 4- Upload de tout le dossier de l’ancien domaine vers le nouveau dossier (blogdecodesign.fr) 5- Création d’une nouvelle base de données 6- Upload de la base de données téléchargée au point 2 dans la nouvelle base de données 7- Exécution des lignes de commandes suivantes pour mettre à jour la base de données (source my digital life): [...]

  • Thanks for sharing how to move WordPress blog to new domain or location.

  • A really great help after moving my wp-installation. Made my day :) Thanks

  • Thanks for this article.

  • this occured to me after moving from one webhost to another. i couldnt login as admin.

    tried alot of the cheap fixes but the cheapest of all worked:

    http://www.village-idiot.org/archives/2007/05/22/

    be sure to delete emergency.php after yer done!

  • Hey again! Forgot to mention that I also had to change links to images inside post content!

    Like this:

    UPDATE wp_posts SET post_content = replace(post_content,"http://somedomain.com/newdir","http://somedomain.com/&quot ;) ;

    The method is always the same, find the old link in the table fields and replace by the new one.

    Bye!:)

  • To fix images path after moving wordpress to another domain or directory you need to update wp_postmeta and wp_posts so that every link related to posts link to the new wp_content location. We need to do a find and replace in some tables of the database. Using phpMyAdmin You could use the following SQL code to search and replace de links.

    UPDATE tablename SET tablefield = replace(tablefield,"findstring","replacestring");

    One example would be:

    UPDATE wp_postmeta SET meta_value = replace(meta_value,"http://somedomain.com","http://somedomain.com/newdir&quot ;) ;

    UPDATE wp_postmeta SET meta_value = replace(meta_value,"http://somedomain.com","http://somedomain.com/newdir&quot ;) ;

    or the other way round depending on your case… (this was mine – changed to account root)

    UPDATE wp_postmeta SET meta_value = replace(meta_value,"http://somedomain.com/newdir","http://somedomain.com&quot ;) ;

    Note: You can use similar expressions to change links for "wp_posts" table, in this case the field to change is "guid".

    Note: In my case I had to Update Permalinks in WordPress Admin->Options->Permalinks to update global linking.

    IMPORTANT: Before changing any table fields look carefully at the field values of the tables in the database so you can decide what values to change.

    This solved my migration of wordpress because after changing files to the server account root directory everything was pointing to the old URL.

    Hope to help, I know what you guys are going through! I had this problem a few days ago.

    Sorry if my English let You down but I'm just a poor Computer Engeneering Student from Portugal :) Have a nice life! Peace!

  • [...] to mydigitallife for the hints on how to do [...]

  • i disabled all plugins, and the site worked again. maybe this helps. bye

  • You rock and fixed my site. Gracias.

  • These SQL statements made my day a lot easier. Thanks!

  • hey, i followed these instructions, but wordpress now just wont display anything. i get a white page when opening index.php… anyway, i can display single pages with example http://url.com/wordpress/?p=123

    strange is that i won't find any php errors, httpd errors or anything alike. any suggestions?

    samuel

  • Thank you so much for the above instructions. You just saved me a lot of time! Much appreciated.

  • [...] is to follow these instructions. I did. Result? All images became broken after the move. I followed these instructions to fix them in my SQL database. No luck. The results from the SQL queries stated that [...]

  • [...] is to follow these instructions. I did. Result? All images became broken after the move. I followed these instructions to fix them in my SQL database. No [...]

  • THANKS!!! I thought I screwed things up royally by trying to organize my domain (and my life). This saved me.

    Cheers

  • [...] article en anglais chez MyDigitalLife explique également comment déplacer son blog WordPress. C’est une méthode très proche de [...]

  • Thanks so much for this! I can't believe this info isn't on http://codex.wordpress.org/Moving_WordPress already! I've been suffering through all sorts of 404's ever since following those instructions!

  • What's wrong with using the builtin Export-Import functions and then just install a plugin to redirect the URLs?

    http://rmarsh.com/2006/09/23/moving-your-blog/

Pages: 1 2 3 6

Leave a comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Subscribe

Free email subscriptions
Get latest updates in email for free:

Translate This Page