How to change links within wordpress posts after migrating!

Now that I got my site up.

I will check for a few things to make sure the pages and content are correct.

I click on the page Indian Mom’s Reviews4Kids.

I see everything fine. In the last paragraph, I see a few links to other pages.
My site page with correct site name and link name

I click on School Reviews.
The page which opens is not in my site www.madhuriesingh.com, but it opens the page in www.madhuriesingh.wordpress.com !!! :(

My links within posts directs  to wordpress blog

Obviously the links do not update when the wordpress is migrated !

I have to change all the links myself.
SO I click phpmyadmin and click the table that is for this website.
click myphp to goto tables

Now I click the table meant for this website. madhurie_wrd01
Click the table for which the links have to change

Now I select wp_posts in the table madhurie_wrd01.
Then I click export button. And save the sql file.

export the wp_posts to edit the links

Now I open the wp_posts table in any editor, find and replace all www.madhuriesingh.wordpress.com to www.madhuriesingh.com
Save the file.

find and replace all links

Now I go back to myphp and drop the wp_posts table.
drop wp_posts table to import updated file

Now I will import this updated wp_posts.sql file back into the tables lists.
import back changed wp_posts file

There I am done with my changing of all the links that were pointing to the wordpress blog back to my site posts. :)

Now lemme test the links again.

I click on the School Reviews link in the page Indian Mom’s Reviews4kids of my site www.madhuriesingh.com

Yippy! I am taken to the correct page School Reviews within my site. :)
my links corrected page

ANOTHER Method for people who are more dare devils or can understand the sql terminology is as follows:

Options means the Identifiers, which are specific only for a blog. So OPTIONS for BLOG1 will be different from OPTIONS for BLOG2:).

These Identifying elements or the Options are like the Blog name, the Blog URL, The Blog Tag line, the admin email address etc. All these are found in a table called Wp_Options.

To update WordPress options with the new blog location, I used 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’;

So mine will be UPDATE WpOnly4Kids_Options SET option_value = (replace(option_value, ‘http://www.madhuriesingh.wordpress.com’, ‘http://www.madhuriesingh.com’) WHERE option_name = ‘home’ OR option_name = ’siteurl’ ;

so wherever the wordpress link is present but not within the posts , the link will be replaced.

I will have to change the url of each post. These are the permanent links of each of my articles. These also need to be changed, else they will take me back to my wordpress blog site. When using wordpress.org front tool wp-admin page to import the XML file from old blog to new site, the wordpress takes care of all these changes. But executing this SQL query once will not harm in any way and might be good in case there is some url that was missed (?) out.

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 (fixed hard coded) instead of relative URLs (flexible codes which change with whenever the location of posts stored changes), 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’);

UPDATE wpOnly4kids_posts SET GUID = replace( GUID, ‘http”//madhuriesingh.wordpress.com’,'http://www.madhuriesingh.com/Only4Kids’);

There are a few places where I have linked one post to another. I will have to change these urls also. I use Pages of my site as mini index of related topics. These pages contain urls of each article that I wish to group together. SO when I moved the blog, these remained unchanged. The moving of Posts will not affect the content of my posts or articles or page. So if these urls within a post need to be changed, I have to either do it the way I explain right at the beginning of this article or execute a small query in SQL.

So if I have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after I move the blog location. I 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’);

UPDATE wpOnly4kids_Posts SET post_content = replace(post_content, ‘http://madhuriesingh.wordpress.com’,'http://www.madhuriesingh.com/Onlyforkids’);

SO now you are turning into a DATABASE manager too :) . Keep it up !!!

You must be logged in to post a comment.