Question

Let's say I have a wordpress site on a subdomain.

Initially, I created the site with "www." >>> www.mysite.mainsite.com

Now, I'd like to change site url to only mysite.mainsite.com without www anymore.

I can change it via Settting > General but I checked the database and I found that all of my images in media library (guid field of the posts table) are still having www.mysite.mainsite.com with www which I don't want it anymore.

I also found this thread related to this Changing www prefix in General Settings and Interior Links

But anyone can suggest if it's risky to do that or not? Will the code there usable for today?

Thanks

Was it helpful?

Solution

I have updated the URLs stored in the database when the domain has changed.

Here are the things to watch for:

  1. In the posts table, the post_content will have any embedded links. These you can change without issue.
  2. 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.
  3. 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.

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top