• I know this has been asked a number of times in this forum, but I’ve never had what I feel is a reasonable explanation as to why WordPress stores internal links (ie links to other content on then site) with the domain name, ie as full absolute URLs. Surely this makes the most standard web development workflow very brittle. This workflow is some variation on this:

    1. Develop site on dev server using dev URL, eg https://dev.testserver.com/
    2. Once complete and fully tested move to live server and live URL, eg: https://www.example.com/

    Doing this breaks all internal links in wp_post.post_content as far as I can tell.

    Surely the links should always be stored relative to the root of the site, eg:

    Good: /about-us/
    Bad: https://dev.testserver.com/about-us/

    I find it hard to believe I need to do a search and replace on the database before putting a site live, but after doing testing. This seems nonsensical to me as it is error prone.

    Sure, for new sites with previously unused domains you can get away with this by putting the site behind a server level password for a while. But if you are doing a complete redevelopment of an existing site, there’s no way to test the final version of the content before putting it all live.

    Excuse the long post, but I find this just so bizarre, that I am wondering if I am doing something wrong or if there is a way to alter my development methodology to avoid this problem?

    Thanks in advance for any explanations and/or workarounds,

    Robin

Viewing 5 replies - 1 through 5 (of 5 total)
  • You could argue that if you’re going to change the way links within posts work it should be linked based on post ID, as otherwise, if you change the slug, it fails (regardless of relative or absolute URLs).

    Also, a lot of people that develop locally with have URLs like
    https://localhost/site1
    https://localhost/site2 etc

    If you start links as /about-us/ it will do it relative to localhost and not that site. Using absolute URLs will only work if you work in the same folder relative to the root on both dev and live. (Yes, I’m aware you can use /etc/hosts to get around this).

    Doing a simple search and replace can be error prone as if it changes the URL within serialised arrays, they will break. A great tool to get around this (and one that’s not let me down since I started using it) is https://interconnectit.com/124/search-and-replace-for-wordpress-databases

    Thread Starter rmassart

    (@rmassart)

    Hi Damian,

    Thanks for the response.

    I hadn’t thought about the local development scenario you mentioned, so I can at least understand now that there are more issues than might at first be apparent (at least to me!).

    Can I ask you how this script you link to is any different to dumping the database to a textfile, doing a file based search and replace and loading the entire dumpfile back into the database? I am not sure I really understand the issue with the serialised arrays.

    Regards,
    Robin

    When you serialize and array/object, it stores the length of data items within it. If you then do a simple search and replace, and change the length of some of those content items, the length is no longer correct, so the whole serialized array/object becomes corrupt.

    Below is a very trivial example using the wp_capabilities usermeta for the admin:

    This is how it should look

    a:1:{s:13:"administrator";s:1:"1";}

    If I then do a simple search and replace, changing “administrator” to “author”, I’d end up with

    a:1:{s:13:"author";s:1:"1";}

    But it should be

    a:1:{s:6:"author";s:1:"1";}

    The s:13 needs to change to s:6 so that it knows the correct length of the following data.

    The script I linked to takes care of this by unserializing and reserializing the data, so the lengths stay in tact

    Hope this clears things up

    Thread Starter rmassart

    (@rmassart)

    OK, so a search and replace on the SQL dump of a WordPress database to change the site’s URL from https://www.devsite.com to https://www.site.com could be problematic if say there is a serialised object that contains https://www.devsite.com in it.

    What would happen in WordPress if a serialised object is corrupt?

    Thanks,
    Robin

    This is a question that I know a lot of folks have been struggling with for a while now. I have heard really good things about the BackupBuddy plugin which claims to allow you to do just what he would like to do and do it relatively pain free. Can anyone vouch for this, I’m considering purchasing it and implementing it on my sites.

    The dev version is $197 but you get several other plugins in the pack, plus you get unlimted use and auto upgrade on all of them. It’s hard to hate on that. Anyone have experience with it, you dont have to get the dev version but it could streamline your problem. They do have issues with some host such as Dreamhost though.

    https://pluginbuddy.com/combos/

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Relative/absolute URLs and developing a site’ is closed to new replies.