0

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

3
  • 1
    Sure you can use that solution. That will work fine but keep a backup of your database in case something wrong happened while processing your queries.
    – Robert hue
    Nov 14, 2014 at 4:55
  • Thanks @Roberthue May be you can suggest some more about this? Actually, my intention is to make CloudFlare (I'm new to it too) cache my files correctly and I need it to cache the non-www version of the files. So that's why I need to modify its url. Do you happen to know if we can configure cloudflare to cache www subdomain (so that I may not have to modify the database)? (I searched but found only how to add subdomain but no one mentions about subdomain with www). Thanks! Nov 14, 2014 at 5:36
  • You can use W3 total cache plugin. It has option for setting up many CDN service providers. You just need to add your credentials.
    – Robert hue
    Nov 14, 2014 at 6:46

1 Answer 1

1

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.

1
  • This is new to me. I tried remove www from url by modifying the database many times yesterday but I always have some problem with meta values and I don't know why. You make it clear to me about serialised data. Thanks! Nov 15, 2014 at 7:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.