I talked about changing the URL paths of images and links for the old posts will be based on the 404 not found error generated through traffic, one by one. Apparently, this was a bad decision. I don’t expect the traffic go up so quickly after I added these old posts. It seems that they still are more popular than my new ones. Therefore, I decided to search for a solution to replace some parts of url for the links (and images) in the old posts with the current url format so that it can direct them to the correct file locations.
During the research, I stumbled across MySQL replace function. I thought that it could come in handy when replace certain phrase within some posts, such as old links and image links. And here are the steps:
- Login to cPanel of your web host.
- Find and login to phpmyadmin.
- Go to the database which your WordPress installation resides.
- Click the SQL tab and type the following codes into the text box:
update wp_posts set post_content = replace(post_content, ‘find this text’, ‘replace with this’);
Replace “find this text” with the text or phrase or whatever you want to be replaced, and replace “replace with this” with the text you want to replace. For instance, mine was
update wp_posts set post_content = replace(post_content, ‘robbychen.com/oldBlog’, ‘blog.robbychen.com’);
- Click Go button and the text is changed in the database.
Now that almost all the links were fixed (at least I think), I still will continue monitoring the 404 errors to see which links are missed from the above code until there are no more 404 errors.
If the above code could not work for you, you can’t understand one or more of above steps, or you have other solutions to replace the text across multiple posts, leave a comment below.