0

I have a site which I moved from one server to other. In source site the wp-content was external and maintained by hosting provided.

After migrating it to new server I changed all the urls and accoring to the new site and added the WP_CONTENT_DIR and WP_CONTENT_URL in wp-config so that the external folder is picked up by the site.

But the problem I faced is mostly all the urls present in the DB gets changed as per the WP_CONTENT_DIR I have mentioned in wp-config, but few doesn't.

SO can anyone tell me how wordpress handles the external wp-content dir after migration or how wordpress manipulates the urls present in the wp_posts table.

Example: my orignal site is http://www.example.com and the wp-content is served from /srv/htpdocs/wp-content which is handled by the hosting provider automatically.

Now I moved my site to same url but to some other hosting.

As the hosting provider is different It is not handled automatically. So, I added WP_CONTENT_DIR as '/var/www/html/srv/htdocs/wp-content' and WP_CONTENT_URL as 'http://www.example.com/srv/htdocs/wp-content'

So now link like 'http://www.example.com/wp-content' gets automatically converted to http://www.example.com/srv/htdocs/wp-content while visiting the site. But few links present in the wp_posts table gave 404 error because they didnt get changed as per the WP_CONTENT_DIR.

Can anyone tell me the reason behind this?

  • Changing WP_CONTENT_DIR and WP_CONTENT_URL won't change the URLs for any images that have already been added to posts. This is because when an image is added to a post the URL of the image is hard-coded into the HTML as the URL at the time of insertion. To update existing URLs you'll need to do a search replace in the database. Tools like WP CLI or Search Replace DB can help with that. – Jacob Peattie Jul 3 at 11:43
  • As mentioned in the example I have the url in a post like example.com/wp-content/uploads/a.png. But when I open the post containg this url the url gets converted to example.com/srv/htdocs/wp-content/a.png. It is happening that is the reason I posted this question. – Sumit Sharma Jul 3 at 13:04
  • Whenever you move URLs you really need to use a plugin or CLI tool to search and replace to update the URLs. WP stores some URLs in a serialized manner which can cause errors like you're seeing. If you have a backup of how the site was before you moved it, running a search and replace plugin on that would be the cleanest way to update things. – WebElaine Jul 3 at 13:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.