So I'm developing my sit in a WAMP environment with URL http://localhost:8080/wp1/ with the eventual plan to migrate it to live on the interwebs. I just noticed in my pages when I upload the images, it's using an absolute src like http://localhost:8080/wp1/wp-content/uploads/date/path/to/image.jpg and this is going to be troublesome when I try to migrate.

Looking online I see people say the answer is, "It's so easy to do a find and replace in the database once you migrate," but that's "so easy" for them and maybe not for someone who has ALWAYS had some kind of issue during a WP migration.

I tried installing a PHP in Posts plugin and added the get_stylesheet_directory_uri to the paths and that worked for getting the images but I suppose the plugin wasn't compatible with the newest version of WP because it caused Strict Standards errors after every page update afterwards so I had to abandon that trial.

Is there no way to develop the site using relative URLs so that migration is a breeze? Is there maybe a built-in method or shortcode?

  • 2
    I've always done a database find/replace - once you get the hang of it, it's quite simple and reliable. Using a plugin for this seems more cumbersome, especially if you have to always add get_stylesheet_directory_uri. I'm happy to provide a more detailed step-by-step if you are open to learning how to reliably do a database migration.
    – Ryan
    Commented Nov 9, 2015 at 17:38
  • A plugin doesn't seem like the absolute ideal approach, no. I'd rather just have a shortcode that is added or something like that and I'm researching that idea. I'd appreciate some step-by-steps if you have the time because if it becomes the only option I have it would be good to have that info.
    – o_O
    Commented Nov 9, 2015 at 17:51

2 Answers 2


The answer is very simple. Learn how to define virtual hosts in MAMP (or XAMP, whatever you use), change your computers hosts file to point the domain to This should solve any URL related issue.


Asking for a best practice might bring down the the "off-topic" hammer of WPSE. It certainly opens up a discussion and opinions can start flying.

Personally, I second the notion that Ryan expressed in his comment. Once you've done a few of these, the find/replace approach is so reliable and lightweight it's the only way I move sites. No need for plugins or lots of extra work to avoid a fairly simply (although frightening) step in a site launch.

The challenge is in the details of course. Modifying only what is changing in the URL prevents problems and this approach has worked for me and my team for years.

Before doing anything, backup, backup and backup, DB copies are small files generally, make 2!!

  1. Build locally as you wish, avoiding URLs in your theme template files. A DB search/replace will not update your PHP or other theme/plugin files. Always use WP's helper functions, such as [site_url][1] and [get_stylesheet_uri][1] among others.

  2. When you are ready to move to the public web server, move your files and import your DB.

  3. Upload one of the Interconnect IT S&R scripts (personal preference - I use the older stable V2) to your WP root. Other search & replace tools exist and you could do this manually of course. The problem to avoid is URLs stored in serialized arrays. A simple text editor can make a mess of this or simply miss the serialized data.

  4. Search and replace ONLY the bare minimum needed. If you are moving from "localhost/example.com" to "example.com" do not add trailing slashes, etc as this will cause the S&R operation to miss some instances in your DB.

  5. Before updating your public DNS for the domain name, test the site with a change to your local hosts file. This way, you can view the entire site as the rest of the WWW will when you do make the DNS change. No stress testing before launch. If there's a mistake, it's easy to dump your DB, reimport and fix the problem.

  6. Delete, delete, delete. Leave the S&R script on your site is a bad idea. Read those warnings and remove the script when you are finished.

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.