Issues with migrated content URLs after moving from Wordpress to Hugo

Hi everyone,

I’ve recently migrated my site from WordPress to Hugo and have encountered some issues with URLs in my content. My old WordPress site had the following base URLs:

Old base URL: http://localhost/mitra
New base URL: https://www.example.com
Old asset base URL: http://localhost/mitra/wp-content/uploads/*year*/*month*/
New asset base URL: https://www.example.com/images/

After converting my content to Hugo format, I noticed that many internal links and asset URLs (especially images) still point to the old localhost URLs. I need to update these URLs to match my new Hugo site structure.

Example of the current content:

Currently, there is a surge in the sale of Cucak Rowo birds at [breeding farms](http://localhost/mitra/peternakan "breeding farms") across Indonesia.

 ![Image](images/indukan-300x169.jpg)](http://localhost/mitra/wp-content/uploads/2021/11/indukan.jpg)

Desired result:

Currently, there is a surge in the sale of Cucak Rowo birds at [breeding farms](https://www.example.com/peternakan "breeding farms") across Indonesia.
 ![Image](https://www.example.com/images/indukan-300x169.jpg)](https://www.example.com/images/indukan.jpg)

articles already converted into markdown and placed in post directory and i use this script to convert wordpress post into hudo .md files

I’ve been trying to manually update the URLs, but this is quite tedious given the amount of content. I’m wondering if anyone can suggest a more efficient method to batch update these URLs across my Hugo project. Perhaps using a script ,notepad++ or specific tool?

Any help or guidance would be greatly appreciated. Thanks in advance!

There’s no need to use complete, absolute image URLs in the MD files. If you place them were Hugo can find them (either in assets or static directory, depending on your partials and image render hook.

Using absolute URLs like you try to do is counter productive if you are running hugo server , too.

this line

 ![Image](images/indukan-300x169.jpg)](http://localhost/mitra/wp-content/uploads/2021/11/indukan.jpg)

resulting in

http://localhost/mitra/post/123/images/indukan-300x169.jpg

also everything in

http://localhost/mitra/wp-content/uploads/*/*/*

is basically 404

As @chrillek mentioned you schould not use hardcoded links but rely on Hugos rendering on markdown url ofc you will have to get your config right.

You will still need

Search replace of the old base url and there are mutiple options. Perl, sed, aek, grep. Also editors like notepd++ or vscode offer batch replace incl regex. But this is off topic and you will find your answer on stackoverflow or similar.

Put your images in a place where hugo can find it. static folder, assets or use the mounts option of hugo

Yes, I understand about that irkode. It’s just that the conversion result from wordpress-export-to-markdown has a format like the one I mentioned above. All attachments have been moved to the /asset/images folder. (im woking on windows )

The issue with the post URL that adds the image path like:

http://localhost/mitra/post/123/images/indukan-300x169.jpg

I believe is caused by the [Image](images/ code, where images does not have a leading slash.

However, the more challenging part is dealing with the http://localhost/mitra/wp-content/uploads/*/*/* URLs.

I would be very grateful if anyone on this forum could help me with the regex for this.

=============
i fix it using python script by chatgpt

thank you

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.