Support » Fixing WordPress » Moving WP site to new domain – media URLs not working

  • I ran into this issue after moving a WP site to a new domain. I built the WP site on an internal staging domain–say, stage.mycompany.com. Once it was ready, I moved it to it’s live domain (say, live.mycompany.com).

    Besides issues around logging in (which I worked around), I went to the admin page and any setting that was still referencing stage.mycompany.com I changed to live.mycompany.com.

    However, I noticed that the media URLs were broken (still referencing the stage.mycompany.com domain). After some digging, I realized that posts store the full resolved URL in posts.post_content in the DB. I also noticed that a few plugins also follow this pattern and store settings with the full resolved URL in options.option_value.

    To work around this I had to run the following MySQL update commands:

    **** WARNING: BACKUP YOUR DB BEFORE DOING THIS ****
    update posts set post_content = replace(post_content, "stage.mycompany.com", "live.mycompany.com");

    update options set option_value = replace(option_value, "stage.mycompany.com", "live.mycompany.com");

    I’m not sure if there is a smarter way of doing this (I assumed setting the site URL in the admin panel would “Just Work”(TM))… apparently not.

    Perhaps there’s a potential for a new WP feature or plugin that could provide a one-button (set my site URL to this) and handle all of this automatically.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Moving WP site to new domain – media URLs not working’ is closed to new replies.