RazorSPoint
RazorSPoint

Correct urls in WordPress after moving the domain

Update URLs in the MySql Database after moving your Wordpress Website.

Sebastian SchützeSebastian Schütze

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.

Broken image urls cause the image not to load.

Broken image URLs cause the image not to load.

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.

Searching in the MySQL Table (PhpMyAdmin) for table entries which still have the old URL.

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!

One of the results still show the old url.

One of the results still shows the old URL.

 

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. 😉

The pasted MySql query to change the urls.

The posted MySql query to change the URLs.

As you can see (if you can ready german 😉 ) 183 entries have been edited and successfully changed.

183 database entries where changed on my posts.

183 database entries were changed on my posts.

And Voila all images are corrected.

Urls to the images are correct now.

URLs to the images are correct now.

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:

http://www.mydigitallife.info/how-to-move-wordpress-blog-to-new-domain-or-location/

 

Sebastian is an Azure Nerd with focus on DevOps and Azure DevOps (formerly VSTS) that converted from the big world of SharePoint and O365. He was working with O365 since 2013 and loved it ever since. As his focus shifted in 2017 to more DevOps related topics in the Microsoft Stack. He learned to love the possibilities of automation. Besides writing articles in his blog and German magazines, he is still contributing to the SharePoint Developer Community (and PnP SharePoint) to help to make the ALM part a smoother place to live in.

Comments 0
There are currently no comments.

This site uses Akismet to reduce spam. Learn how your comment data is processed.