There may instances where you are changing domain name or moving wordpress from a directory to root or vise verse and you have content in database. As wordpress saves full urls in database you will need to change urls so that you do not get 404 error on pages,posts,comments and images.
Very first step is to backup your database so that have saved copy of database on your computer just in case you make mistake and have go back to original install.
Log in on server and go to phpmyadmin and click on export and save all tables as file.
There are three ways you can change urls
Use Notepad++ and open the downloaded file and search and replace the urls and save the file as some other name so that you still have the backup and drop tables in database and import the file with changed urls.
The easy way is to change the urls in database directly and as you have backup you are fine to use this method.
To update WordPress options with the new blog location, use the following SQL command, this will change your urls that are set in Settings >>>General of your wordpress.
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';
To change URLs of the WordPress posts and pages, which are saved in wp_posts table as guid field. The URL are saved as absolute URLs instead of relative URLs, so they need 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 links internally within blog posts or pages with absolute URLs, these links need to be changed else they will point to wrong page 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.
Note: You need change prefix if you are using other then wp_
Replace http://www.old-domain.com and http://www.new-domain.com with your urls
You can install this plugin Velvet Blues Update URLs
and follow the instruction form the plugin page.
Once You have made changes you will need to reset permalinks if used.
We would like to thank you for Visiting our website . Your opinion is important to us. We would like to invite you to write a review about your experience Select Number of Stars for the review and write review in box and Click on Connect Preferred Button.