I'm helping a friend fix some problems with the migration of their word press site and I don't use WP much, but I know PHP/SQL/CSS/HTML/etc. They installed and built the site on "JunkDomain.com" and moved it to a different server "test.domain.com" where "domain.com" will be the final live version.

The junkdomain.com version that was moved over has a lot of absolute url references using JunkDomain.com. When he moved it over he linked the JunkDomain.com file system up as a mirror and didn't notice that everything on test.domain.com was really pulling a lot of stuff from JunkDomain.com.

I've found WP using the absolute urls to junkdomain.com in:

  • widgets
  • html page links
  • image src's

Once junkdomain.com goes away, all his stuff is going to break. I could just search & replace in the SQL, widgets, etc. But I thought I'd ask here since I also plan to go from test.domain.com to domain.com.

What's the best way to remap these to the test.domain.com? and What's the best way to manage rolling out from test.domain.com to domain.com?

Whats the best WP practice to use absolute or relative URLs for widgets/images/etc?


The chosen answer worked -- See option #2 from this document http://codex.wordpress.org/Moving_WordPress

If you do a search and replace on your entire database to change the URLs, you can cause issues with data serialization, due to the fact that some themes and widgets store values with the length of your URL marked. When this changes, things break. To avoid that serialization issue, you have two options:

  1. Only perform a search and replace on the wp_posts table.
  2. Use the Search and Replace for WordPress Databases Script to safely change all instances. (If you are a developer, use this option. It is a one step process as opposed to the 15-step procedure below)
  3. Optionally, you can also use an online tool (in case you don't want to bother with uploading scripts to your server) Online WordPress Serialized PHP Search and Replace which allows for replacing an old domain or URL with a new one while fixing the serialized data at the same time.

1 Answer 1


Absolute or relative URLs are one of those eternal debates, but what you have to know in WordPress context is that it has strong affinity for absolute links. The logic is that changing absolute links in general is easier than changing level of relative links when necessary.

The second point you need to know is that WordPress stores a lot of stuff in serialized representation. Running simple string replacement on database or database dump is likely to break data.

So what you need is specialized serialize–aware search/replace tool. There are quite a few solutions around, standalone or as functions of backup plugins. I am partial to Search-Replace-DB personally.

  • Thanks. Do you know if themes are serialized? I've tried the text search & replace method, but it appears that perhaps some theme elements and plugins were not updated.
    – user6972
    Oct 28, 2014 at 0:53
  • Note this only applies to database, you might have URLs in code too, which is separate matter. It doesn't really matter what is serialized, since a lot of things can be (core and extensions either).
    – Rarst
    Oct 28, 2014 at 8:55
  • I guess I meant that I see some theme based configuration in the database. Also, if I make edits to the 'options' database the widgets tend to disappear. So I'll try your suggested tool and see how it goes.
    – user6972
    Oct 29, 2014 at 16:59

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.