Some days ago I finally could set up my new WordPress theme. I also changed the blog URL from the subdomain http://blog.razorstudio.de to https://www.razorspoint.com. With that, I had to change the base URL in the WordPress settings. That was an easy job. But then I came across the problem that most of the image URLs were broken. The problem was that they still pointed to my old domain.
Check the MySql Database
So what should we do now? I figured I need to update the post content. To do that you should go to your database admin tool. In mine and generally most cases this will be „PhpMyAdmin“. So if you open that tool and choose your WordPress database you can make a search query how much of your content is affected. You can get a good overview if you navigate to the „Search“ tab of PhPMyAdmin and search for part of your old URL surrounded by ‚%‘ (wildcard placeholder). The only other thing you need to mark is your WordPress post table „wp_posts“ in the tables field.
After you hit search you will see how much content is affected. In my case, it was nearly 200 entries. Not so much but I haven’t written that much in the last couple of… Uhm YEARS. 😉
But in the next image, you can see that the content still points to the old URL „blog.razorstudio.de“. So let’s change that!
The MySql Query to correct the broken URLs in WordPress
The query we will need is the following:
UPDATE wp_posts SET post_content = replace(post_content, 'http://blog.razorstudio.de', 'https://www.razorspoint.com');
with that query every old URL with the new one is replaced. Just make sure you put in your URLs and really make sure that the new URL is spelled correctly. You don’t want to change the old wrong URL into a new wrong URL. 😉
As you can see (if you can ready german 😉 ) 183 entries have been edited and successfully changed.
And Voila all images are corrected.
Just be aware that there could be more tables in your database. If you want to check if there are more entries in other parts of your WordPress database, then have a look here:
How to Move WordPress Blog to New Domain or Location