How to manually find and replace URL instances in a WordPress database to migrate from one domain to another.

Assuming you are working on the SQL file, and wanting to migrate the site from e.g. www.domain.com to s.domain.com.

There will be many instances of e.g. https://www.domain.com within the SQL file which you will need to replace with e.g https://s.domain.com.

Whilst this sounds straightforward enough, you also need to bear in mind that WordPress also stores URLs within serialised data structures in some cases.

A classic example might be an ACF link field, where the link URL is stored as a serialised string in the database.

The problem you can run in to if you just blindly find-and-replace all instances is that the string length changes, and the data cannot be properly parsed when your new instance loads it from the database.

An example of a URL embedded within serialised data in the SQL file is as follows:


a:2:{s:2:\"id\";i:4024;s:3:\"url\";s:134:\"https://www.domaintester.co.uk/wp-content/uploads/elementor/screenshots/Elementor-post-screenshot_1692_2025-09-17-11-29-05_319f35ea.png\";}

The problem if you just replace www.domaintester.co.uk with s.domaintester.co.uk is that the latter is 2 characters shorter than the former, therefore you also need to update the s:134 declaration.

To effectively replace this URL you would replace the above with the following:


a:2:{s:2:\"id\";i:4024;s:3:\"url\";s:132:\"https://s.domaintester.co.uk/wp-content/uploads/elementor/screenshots/Elementor-post-screenshot_1692_2025-09-17-11-29-05_319f35ea.png\";}

Both the string length, and the URL are updated.

A process for applying this manually to an SQL file would be as follows:

1. Search the file using GREP / regex using a pattern like so:


s:\d+:\\"https://www\.domain\.com

As a starting point this will identify all the serialised URLs in the file.

2. Methodically update the regex pattern to find every plausible length of string in the file, and replace it accordingly.


s:22:\\"https://www\.domain\.com

Replace with


s:20:\\"https://s\.domain\.com

Then


s:23:\\"https://www\.domain\.com

Replace with


s:21:\\"https://s\.domain\.com

Then


s:24:\\"https://www\.domain\.com

Replace with


s:22:\\"https://s\.domain\.com

Etc.

Repeat this process until all instances have been replaced. You can re-use the pattern in stage 1 to find any stragglers.

Only once you have updated all of the serialised URLs, can you then do a straightforward find-and-replace on the remaining ones.

Remember to check for e.g. https://www.domain.com AND https://domain.com AND http://www.domain.com AND http://domain.com!

Mobile Menu