Moved a WordPress installation and it’s linking to the wp-upload folder?

UPDATED : I rushed this one out. I’m now adding more meat to the bones on what this post is about!

If you use a development environment for the WordPress sites you build you may have come across a rather annoying issue. When you move the WordPress site to the live environment, any links to assets, such as uploaded documents or images are still relative to the development environment. Depending on how many links you have, you may just choose to re-link all the files / images to the new address. However, when you start working with hundreds of assets, it’s a lot of work to run through.

Alas, no worries. There’s an easy fix.

I recently moved a WordPress installation from “development” to “live” and was having great issues with the FTP server konking out every 2 minutes. Rather than duplicating folders and folder structures (which is a nasty hack) whack this gem of a redirect into your .htaccess file on the root of your server, and you’ll be away :

RewriteEngine on
RewriteRule ^FOLDER/(.*?)/?$ NEWFOLDER/$1 [L]

This code simply routes any request for a file in the old folder to a new folder. For example, say your development site was in a folder named “dev”, the code would be :

RewriteEngine on
RewriteRule ^dev/wp-content/(.*?)/?$ wp-content/$1 [L]

I hope this helps!

This code was kindly put under my nose by my good developer chap @samwilliamh on twitter.

This entry was posted in Resources, Tips. Bookmark the permalink.
  • Test

    I think this article needs a little more explaining, its not clear what the problem was or how this could be used? Is the .htaccess required in the root or the root wp folder? I ask cos I’ve been playing with a similar issue this week?

    • Anonymous

      Although you posted a good question, it would be nice if you didn’t use an anonymous title :)

      I’ve now added some meat to the bones of this post so it makes a little more sense. Was in a rush the first time i posted it. It won’t happen again! :)  

    • Anonymous

      Although you posted a good question, it would be nice if you didn’t use an anonymous title :)

      I’ve now added some meat to the bones of this post so it makes a little more sense. Was in a rush the first time i posted it. It won’t happen again! :)  

    • Anonymous

      Although you posted a good question, it would be nice if you didn’t use an anonymous title :)

      I’ve now added some meat to the bones of this post so it makes a little more sense. Was in a rush the first time i posted it. It won’t happen again! :)  

      • Test

        It’s my firstname

    • Anonymous

      Although you posted a good question, it would be nice if you didn’t use an anonymous title :)

      I’ve now added some meat to the bones of this post so it makes a little more sense. Was in a rush the first time i posted it. It won’t happen again! :)  

    • Anonymous

      Although you posted a good question, it would be nice if you didn’t use an anonymous title :)

      I’ve now added some meat to the bones of this post so it makes a little more sense. Was in a rush the first time i posted it. It won’t happen again! :)  

  • Anonymous

    Just remember kids – don’t go hacking around in the .htaccess unless you know what you are doing. Can be big trouble for your site and can result in locking yourself out of your site too. 
    ;)

  • Anonymous

    Just remember kids – don’t go hacking around in the .htaccess unless you know what you are doing. Can be big trouble for your site and can result in locking yourself out of your site too. 
    ;)

  • http://twitter.com/shanegriffiths Shane Griffiths

    Hi Gareth, nice little trick there. I think this would be useful when working between different dev versions or trying something out. I’m not sure as to whether it would be a good idea to use on a production site. Seems abit messy and could contribute to some (very small) latency.

    Have you tried the migrate.php script from https://github.com/ErisDS/Migrate I use this on all my projects when going from dev ->staging->prod

  • @danfast

    Hi Gareth,

    Good tip but would this mean that future changes to content in dev would then be reflected in live. Unless this is aimed at a quick temporary work around while you duplicate folder structures and repoint content?

    Dan