• Hi,

    I’m working on a new theme on my local machine for an existing live site. I was given the live site database and the contents of “/wp-content/uploads” directory to work with.

    I imported the database and updated the ‘home’ and ‘siteurl’ option values to match my local machine.

    Then I notice to my surprise looking at Chrome network inspector, the user uploaded media files are actually loading from my local machine (ie. https://localhost/wordpress/wp-content/uploads/2020/03/image.jpg instead of https://livesite.com/wordpress/wp-content/uploads/2020/03/image.jpg ) I check the post content in the database, the media URLs are still the live site ones. So there must be some automatic filter that changes these media URLs before it is output to the browser? I thought if we change a WordPress site URL, we also had to manually update all those media URLs in ‘post_content’ in the database manually?

    • This topic was modified 4 years, 6 months ago by James Huff. Reason: moved to Localhost Installs since this is a localhost install
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    It can work both ways. In some cases the media URLs are built dynamically so the current site URL setting will be used. In other cases the media’s site URL is part of the static data and you must search/replace all instances of the old URL in the DB for new using appropriate tools like the Better Search and Replace plugin.

    If you want to work locally on data from a live site, instead of changing all the static URLs, you could add the site’s domain to your computer’s hosts file, mapping it to 127.0.0.1. After restarting your computer, your localhost server will respond to domain requests instead of going out on the internet. No need to change any data, nor needing to change it back again when migrating back to the live site.

    The drawback of course is you can no longer access the live site from that computer until the hosts entry is removed. But why would you need to? You’ve a local copy ??

Viewing 1 replies (of 1 total)
  • The topic ‘After changing WordPress Address and Site Address in settings, media URL in Post’ is closed to new replies.