WordPress.org

Ready to get started?Download WordPress

Forums

[closed] Why does wordpress store a full path to content? (8 posts)

  1. studentrob
    Member
    Posted 1 year ago #

    I come from Drupal, and find it odd that WordPress stores full paths to images and requires manual steps to update the site URL when migrating between environments. I cannot think of any reason for having it this way now or at any time in the past. It makes migrating between environments more difficult for first time users and it just feels sloppy. Everyone knows you should not use full paths in case your domain changes. Even the WYSIWYG wants me to set a full path by default when I link to my own content. Can anyone give a reasonable explanation as to why it is this way, and if there are any tickets open for storing relative paths instead of the full one with the domain attached?

  2. esmi
    Theme Diva & Forum Moderator
    Posted 1 year ago #

    Please see the previous discussions on this topic.

  3. studentrob
    Member
    Posted 1 year ago #

    You link to 472 posts. I see some people with the same question as me, one guy who claims it is easier to migrate a site with absolute URLs than it is to migrate one that uses relative URLs (not sure what he is thinking), and some suggestions on how to implement a WordPress migration. I do not see anything about why WP stores domain + full path in various places. Nor is there any explanation why the process of migration between dev/test/prod environments is not more streamlined.

  4. What would you consider a reasonable reason to why?

    I ask this seriously, because the tl;dr of 'Why?' is that WP decided this was the way to go, and now, after 9 years, it's not about to change.

    It works. It's sustainable. It's easier to search/replace a full path in the long run. When you use the built in import/export, it will automagically fix your URLs (vs if you use relative and happen to go from domain.com to domain2.com/wp/, all your relatives will die an ugly death).

    Your migration process can be perfectly streamlined, if you use the tool as intended and build your flow around it, vs the other way around :)

  5. studentrob
    Member
    Posted 1 year ago #

    Ipstenu- anything substantive would do.

    Again, this response is just a defense of the current setup, and does not address specifics. "It's easier to search/replace a full path in the long run," or "It's been that way for 9 years" are not legitimate reasons. Hopefully you do not apply such logic to civil liberties.

    Why is search/replace easier than not having to do so? Do you mean that it is easier to keep the current setup than to change core code? If so, nearly all programming problems are this way!

    Again, I understand there are ways to do the search/replace if you add them to your system, and I also realize that everyone may not need these tools so that is why they come packaged separately.

    What I do not understand is why not fix the simple things, like the action of the link button in the WYSIWYG when selecting your own content to link to, or the uploaded content images and site logo - why not just have these store a relative paths to my own content rather than the absolute url?

    To migrate WP you must take some steps before you can log in to your new site. Other CMSs do not have this requirement, why should WP?

  6. Absolute URLs are easier to change with a global search and replace. Relative URLs are difficult to alter later and make the regular expressions needed to do so much more difficult to create.

    And this is a very common real-world situation I'm about to depict.

    If I have saved all my URLs like this: http://domain.com/wp/foobar

    And I decide I want to move to http://domain.com/foobar

    Then I can search/replace for http://domain.com/wp/ and replace with http://domain.com/

    On the other hand, if I've saved them all as /wp/foobar, then the search for /wp/ runs the risk of hitting other URLs that may also use that. So then I have to search for href="/wp/ and src="/wp/ and hope I get them all. Now I've got at least two searches to the previous one.

    More work.

    Benefits of Absolute URLs:

    • Easier search/replaces
    • Works well with all feeds (relative URLs don;'t)
    • Not having to run a query to check the URL every time you want to load a link or image
    • Easier support with dynamically generated content (if this was a static HTML site, I'd agree with relative URLs, but WP is all dynamic and things get moved)

    Now. talking about changing core is a bigger issue than you mention becuase we must remain backwards compatible (this is a hallmark of WP, and we're proud of it). When you make a big change, you simply cannot break everyone's site ;) Oh and consider Multisite, if you will. Relative URLs there change depending on if you map domains or not, right away, and then they're parsed through a ms-files.php file but have the URL of /file/... - More things to make sure we don't break.

    By the way, the reason this isn't an option is that WP believes in decisions, not options, so making this an optional setting is unlikely to happen. Whenever possible, we like to have a 'this is what it is' and done.

    The move from development to production is a one time thing. It's not hard to do, and if you wanted to make your life even easier, when you build out locally, you could edit your hosts file to have domain.com point to your local site :) (I generally use domain.loc and then search/replace that for domain.com in the end, to prevent any brainfarts on my end, and to make sure I'm looking at the right site all the time).

  7. studentrob
    Member
    Posted 1 year ago #

    I think you are missing my major gripe about how migrations are not streamlined in WP but it they are for other CMSs. Links in post content need not be stored as full URLs, and the action attribute on the WP login form need not contain the full site URL.

    To your points,

    Easier search/replaces

    Even with the current setup you have to do a search/replace for relative URLs too because content editors may have chosen to use them. Surely one could write a plugin to cover the cases.

    Works well with all feeds (relative URLs don;'t)

    When you make a feed obviously you would generate the full URL

    Not having to run a query to check the URL every time you want to load a link or image

    Huh?

    Easier support with dynamically generated content (if this was a static HTML site, I'd agree with relative URLs, but WP is all dynamic and things get moved)

    Is this the same point as above?

    Backwards compatibility

    Nothing about storing newly created URLs as relative ones by default in post content would break old versions of WordPress. Nothing about changing the form's action path would break an existing user's site.

  8. studentrob,

    These are the support forums not the debate forums. If you want to debate try your luck on the WP Hackers mailing list or go through the archives .

Topic Closed

This topic has been closed to new replies.

About this Topic