1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 should relative URLs start with a slash

Discussion in 'XenForo Questions and Support' started by Mr Lucky, Apr 16, 2016.

  1. Mr Lucky

    Mr Lucky Well-Known Member

    I am changing a few links to relative URLs in advance of switching to https. e.g. link to custom smilie folder etc and various bits of html in notices and pages.

    Should relative links start with or without a slash? I notice that appear either work (whereas in Wordpress they only seem to work with the starting slash)

    Is there any reason to not have relative links?

    Thanks
     
  2. thumped

    thumped Well-Known Member

    links starting with / will be relative to the root of your site
    without will be relative to the directory you're currently in
     
  3. Mr Lucky

    Mr Lucky Well-Known Member

    So does that mean better to have them without?
     
  4. Mr Lucky

    Mr Lucky Well-Known Member

    I am doing a test with smilies. One smiley has the slash, the other one doesn't.

    However they both show up fine in a thread, which is odd because they are in an image directory in the root, so the link with the slash should work, but the one without should not work if it is relative to /threads/ rather than the root.
     
  5. Kevin

    Kevin Well-Known Member

    Depends on how the link will be accessed.

    Let's say you have a file named "smiley.gif" and your site URL is wakawaka.com. On your server you have a single folder named images off of your root folder so the full url to the images is wakawaka.com/images/smiley.gif.

    Now let's say you have two pages, one named "page1.html" and is in the root of your web site; the url looks like wakawaka.com/page1.html. The second page is named "page2.html" and it resides in a folder named "docs" off of your root folder; the url looks like wakawaka.com/docs/page2.html.

    Now both page1.html and page2.html is supposed to display smiley.gif when shown to the user.

    If you use "/images/smiley.gif" then the image will be shown as expected on both pages.

    If you use "images/smiley.gif" then it will only be shown on page1 and not on page2 because the URL is interpreted as "wakawaka.com/docs/images/smiley.gif" which doesn't exist.

    With XF everything is served relative to the folder that XF is installed in so that is why right now both links are working for you. If the only thing on your URL is XF and all of your pages are being presented from within XF and all of the content is rendered using XF (eg: a smiley code) then you don't have much to worry about. If, on the other hand, you might have several things installed at your URL and, for example, you have /images/smiley.gif on the server and XF is installed physically in folder named "myforum" (eg: wakawaka.com/myform/index.php") you'll need to use the "/' in front of the relative URL.

    Cliff Notes (or "tl;dr" for the younger generations): You usually can't go wrong with using the "/" in front.
     
    Mr Lucky and Jeremy P like this.
  6. Jeremy P

    Jeremy P Well-Known Member

    That's because XF sets a <base> location, from which all relative links are resolved.
     
  7. Mr Lucky

    Mr Lucky Well-Known Member

    Thanks, very useful.

    I had thought that with /threads/ in the url that would act as if inside s directory called /threads/ (even though we know there isn't one)
     
    Jeremy P likes this.
  8. Jeremy P

    Jeremy P Well-Known Member

    Yeah, that's what it would do if there were no <base> location set.
     
    Mr Lucky likes this.

Share This Page