I have updated the URLs stored in the database when the domain has changed.
Here are the things to watch for:
- In the
posts
table, the post_content will have any embedded links. These you can change without issue. - Again in the
posts
table, the gid would change if you do a global search and replace. This is mostly used with regard to RSS feeds. You can either change them or leave them without much issue unless the RSS GID is important to you. - In the
postmeta
table, this is where it gets tricky. If the field is just a raw string field, then you’ll have no issue changing it. The issue is when the URL is within serialized PHP data.
Why serialized data would break
When PHP serializes a string, it embeds the length of the string. For example, http://www.example.com
becomes s:22:"http://www.example.com";
. Notice the 22
after s:
, this is the string length. If we drop the www
, then the serialized value would be: s:18:"http://example.com";
. If the length is wrong, then the data becomes garbage to WordPress.