How to: Replace Absolute URLs in WordPress Posts Using PHPMyAdmin
30th October 2014
If you’ve moved your WordPress website from one domain to another, one of the associated headaches is changing all of the absolute file paths in your posts and pages. If you’ve inserted an image or a link to another page, they’ll all now be incorrect. One way to fix the problem is to go through each post/page manually updating the URL of every single one of your links and images. BORING. On a big site this is going to take ages, so if you’ve got PHPMyAdmin you can take the sting out of it. Here’s how it’s done:
Log in to your database from PHPMyAdmin. If you don’t know the details or which of your databases you’re using, you’ll find this information in the wp-config.php file in the root of your WordPress installation.
With your database selected, hit the SQL tab. This will allow you to run a SQL query on the database.
We want PHPMyAdmin to go through the posts stored in the database and replace any instances of the old domain URL with the new one. To do that we’re going to use this script, so paste it into the big text box that appears:
UPDATE wp_posts SET post_content = REPLACE (post_content, 'http://olddomain', 'http://newdomain')
NB: You need to make sure the table prefix is right. The standard is wp_ but it make have been changed to something different. You’ll easily be able to tell by looking at the names of your WordPress tables down the left hand side of the screen.
Hit ‘Go’, wait a few seconds and let PHPMyAdmin complete the task in a matter of seconds.
NB: Because this post is more than two years old, and the world of web design and technology moves on so quickly, the information in it may now be out of date