Relative/Absolute URLS

Discussion in 'HTML' started by theo, Feb 7, 2005.

  1. theo

    theo Guest

    Cheers,
    I am somewhat confused over using relative paths, due to the fact that
    different web-servers seem to act differently. Is there a catch-all
    solution for relative paths? One host, if I use /index.htm or
    /tools/search.htm, it will always forever work. Another host, can't find
    graphics or folders. Another host, I always use ../index.htm or
    .../tools/search.htm, and it always works like a charm.
    It's driving me mad, new hosted domain today, which I haven't figured out
    yet. One minute it's fine, resolved, and next time it can't find a thing.
    HELP? Any relative paths are supposedly linked from the root folder. How
    do I determine the root folder? Does anyone know of any good tutorials on
    this particular nightmare?

    cc
    theo, Feb 7, 2005
    #1
    1. Advertising

  2. theo wrote:

    > Cheers,
    > I am somewhat confused over using relative paths, due to the fact that
    > different web-servers seem to act differently. Is there a catch-all
    > solution for relative paths? One host, if I use /index.htm or
    > /tools/search.htm, it will always forever work. Another host, can't find
    > graphics or folders. Another host, I always use ../index.htm or
    > ../tools/search.htm, and it always works like a charm.
    > It's driving me mad, new hosted domain today, which I haven't figured out
    > yet. One minute it's fine, resolved, and next time it can't find a thing.
    > HELP? Any relative paths are supposedly linked from the root folder. How
    > do I determine the root folder? Does anyone know of any good tutorials on
    > this particular nightmare?
    >
    > cc


    There is a similar issue with upper-case/lower-case where the obvious
    solution is to care for case-sensitivity. This means that extra caution is
    needed and on a Window$ host there is no way of testing this for guaranteed
    robustness.

    As for paths, you should always be fine with "../tools/search.htm", for
    example. This should always be relative to the current page. Having said
    that, some crawlers are too (shall I say?) stupid to handle this properly.
    Also, this induces a big cost when moving pages around and changing
    levelling. It's a clear case of trade-offs. The best you can do is stick to
    one host and not migrate too much.

    Roy

    --
    Roy Schestowitz
    http://schestowitz.com
    Roy Schestowitz, Feb 7, 2005
    #2
    1. Advertising

  3. theo

    Toby Inkster Guest

    theo wrote:

    > I am somewhat confused over using relative paths, due to the fact that
    > different web-servers seem to act differently.


    No they don't. Relative URLs aren't even interpreted by the server --
    they're interpreted by the browser. The browser *always* requests
    absolute URLs from the server. The web server *only* has to deal with
    absolute URLs.

    > One host, if I use /index.htm or /tools/search.htm, it will always
    > forever work. Another host, can't find graphics or folders. Another
    > host, I always use ../index.htm or ../tools/search.htm, and it always
    > works like a charm.


    Then I'm guessing you do not correctly understand the difference between
    "../index.htm" and "/index.htm". The first means "find 'index.htm' in the
    directory above the current directory. The latter means "fine 'index.htm'
    in the top directory". If you are in the "first layer" of subdirectories,
    both will mean the same. Otherwise, they'll each do different things.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Feb 7, 2005
    #3
  4. theo

    theo Guest

    > > HELP? Any relative paths are supposedly linked from the root folder.
    How
    > > do I determine the root folder? Does anyone know of any good tutorials

    on
    > > this particular nightmare?
    > >
    > > cc


    >
    > As for paths, you should always be fine with "../tools/search.htm", for
    > example. This should always be relative to the current page. Having said
    > that, some crawlers are too (shall I say?) stupid to handle this properly.
    > Also, this induces a big cost when moving pages around and changing
    > levelling. It's a clear case of trade-offs. The best you can do is stick

    to
    > one host and not migrate too much.
    >
    > Roy
    >



    Roy,
    Thanks for your input. I use templates, and so I can't program each page,
    need a relative url to the entire site, to the "parent directory". The
    .../tools/search.htm works well most of the time. Dreamweaver usually does it
    this way, but lately I've run into sites which don't. Either linux or win
    is the problem, or possibly an issue with quote, "parent directory". I
    haven't figured that out yet, and am wondering how to tackle this issue.
    Thanks,
    cc
    theo, Feb 7, 2005
    #4
  5. theo

    theo Guest


    > in the top directory". If you are in the "first layer" of subdirectories,
    > both will mean the same. Otherwise, they'll each do different things.
    >
    > --
    > Toby A Inkster BSc (Hons) ARCS
    >



    Toby,
    Directnic hosts 4 of my domains, and / whatever always strips you down to
    the parent directory. /index.htm, from any page at any level, will take you
    to the first level index file. I know, it's supposed that the browser
    handles all of this, but why does this only work with directnic?

    I've beat myself down, made a page with 50 links, put it in 4 levels, with
    .../ with / with ../../ trying to find out how to make other sites work the
    same. The slashes and dots do strip you down, but not to the point where
    the same relative link is understood at all levels.

    Leaves me in the position that you speak of, that each link on every page,
    has to be specific and relative, not to the parent level, but to the present
    level.

    Directnic: Maybe I should be asking them...

    thanks....
    cc
    theo, Feb 7, 2005
    #5
  6. theo

    theo Guest

    > Then I'm guessing you do not correctly understand the difference between
    > "../index.htm" and "/index.htm". The first means "find 'index.htm' in the
    > directory above the current directory. The latter means "fine 'index.htm'
    > in the top directory". If you are in the "first layer" of subdirectories,
    > both will mean the same. Otherwise, they'll each do different things.
    >
    > --
    > Toby A Inkster BSc (Hons) ARCS
    > Contact Me ~ http://tobyinkster.co.uk/contact
    >


    Cheers,
    I finally figured the situation. My host, if you enter any bad path,
    you'll
    be instantly brought to the index.htm The root directory only has one file,
    which is the index.htm, and the entire site only has two levels in directory
    structure. This explains my scenerio, that /anything/anything.htm or
    /anything.htm will always get you there. In this case, it's the server which
    gets you there, and not the browser, but due to the structure of the site.

    I tried http://tobyinkster.co.uk/go.htm and it brings me to a 404 page.
    With
    my site, you'll never ever see a 404, but the index instead.

    Thanks,
    cc
    theo, Feb 7, 2005
    #6
  7. theo

    Dan Guest

    Dan, Feb 7, 2005
    #7
  8. theo

    theo Guest

    "Dan" <> wrote in message
    news:...
    > Some relevant info:
    >
    > URLs (URIs), relative and absolute:
    > http://webtips.dan.info/url.html
    >
    > Directories and Default Index Files:
    > http://webtips.dan.info/subdir.html
    >


    +++ A URL with a slash at the start, like "/dir1/dir2/stuff.html",
    +++ references a page at a path starting from the root of the server.
    +++ To be more precise, it starts at the root of the domain name you're in.

    Thanks Dan,

    The path relative to server root was what I was looking for,
    which I'm not sure that Toby mentioned. Wasn't interested
    in climbing up or down notches in the tree.

    I'm still having problems with one domain, actually a sub-domain,
    where the root-relative relative paths don't seem to work. I haven't
    figured
    the root, quite yet.

    Paste follows:
    __________________________________
    Thank you for using the directNIC.com Trouble Ticket System. The following
    response is from a qualified directNIC customer support team member:

    Date: 02/07/05 01:36pm
    From: mbrunson

    directNIC's links should be the same as any other webserver, since
    it's more a function of the client software. There are several ways
    to refer to a page on your site. Let's say you're on the page:
    http://example.com/family/picnic/photo.html And want to link to a page:
    http://example.com/fun/car/engine.html You could add the link in a
    couple ways, such as:
    http://example.com/fun/car/engine.html (absolute link)
    /fun/car/engine.html (relative to the root)
    .../../fun/car/engine.html (relative to the page you are on)

    If you wanted to link to a page in the same directory, let's say:
    http://example.com/family/picnic/menu.html You could do this with the
    following:
    http://example.com/family/picnic/menu.html (absolute link)
    /family/picnic/menu.html (relative to the root)
    ../menu.html (relative the the current page)
    menu.html (relative the the current page the "./" is inferred)

    paste ends
    +++++++++++++++++++++++++++

    Thanks,
    cc
    theo, Feb 8, 2005
    #8
  9. theo

    theo Guest

    I also tried to clairify/change/alter the server root by adding this base
    tag into the head, but no dice either.

    <base href=http://www.domainname.com/subdomains/>

    <base href=http://www.domainname.com/subdomains>

    cc
    theo, Feb 8, 2005
    #9
  10. theo

    Dan Guest

    theo wrote:
    > I'm still having problems with one domain, actually a sub-domain,
    > where the root-relative relative paths don't seem to work. I haven't
    > figured
    > the root, quite yet.


    I'm not sure I understand your problem. A subdomain is just like any
    other domain, except it's third-level (or more) instead of
    second-level, so that if you have the domain bar.net, you can use
    subdomains like foo.bar.net. The principles behind how they work on
    the Web are the same as for "regular" domains.

    If the server is configured so that foo.bar.net serves the main index
    file out of some directory on the server (maybe a different one from
    where the main domain bar.net is served out of), then that directory is
    the "root" as far as URLs in that subdomain are concerned.

    --
    Dan
    Dan, Feb 8, 2005
    #10
  11. theo

    theo Guest

    Dan,
    I did finally find the server root. Now, I can put
    the same exact relative url in all html files, at any level,
    and they'll work. No moving up and down BS,
    having to edit every single file at every level,
    relative to present location.

    For:
    http://domainroot.com/notes/css/positioning.htm

    I can use: /notes/css/positioning.htm anywhere,
    in any file, in any folder, and it will work just fine.

    I have an angelfire subdomain from hell spare site, which is:
    http://angelfire.com/folk/pryopen/index.html

    I must use /folk/pryopen/index.html, in any file,
    at any level, and it will work just fine.

    I tried to use the
    <base href="http://www.angelfire.com/folk/pryopen">
    in the head, to shorten the relative path to:
    /index.htm, but no dice.

    cc
    theo, Feb 8, 2005
    #11
  12. theo wrote:
    > I tried to use the
    > <base href="http://www.angelfire.com/folk/pryopen">
    > in the head, to shorten the relative path to:
    > /index.htm, but no dice.


    With <base>, you would use "index.htm", with no leading slash.
    Leif K-Brooks, Feb 8, 2005
    #12
  13. theo

    Toby Inkster Guest

    theo wrote:

    > I did finally find the server root. Now, I can put
    > the same exact relative url in all html files, at any level,

    [...]
    > I can use: /notes/css/positioning.htm anywhere,
    > in any file, in any folder, and it will work just fine.


    That is an absolute URL -- not a relative URL.

    A relative URL is any URL that does not match the regular expression
    /^([A-Za-z0-9]+\:|\/)/.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Feb 8, 2005
    #13
  14. theo

    Dan Guest

    theo wrote:
    > I did finally find the server root. Now, I can put
    > the same exact relative url in all html files, at any level,
    > and they'll work. No moving up and down BS,
    > having to edit every single file at every level,
    > relative to present location.


    On the other hand, the relative "moving up and down BS" URLs work
    better when you browse the pages on your local hard disk before
    uploading them to a server, so some prefer that syntax on this account.

    > I have an angelfire subdomain from hell spare site, which is:
    > http://angelfire.com/folk/pryopen/index.html


    That's not a subdomain; it's in the main domain of angelfire.com,
    though in a (two-level-deep) subdirectory of its main server root. A
    subdomain would be pryopen.angelfire.com. And since index.html is the
    server default index file, you can cite the URL more short-and-sweet as
    http://angelfire.com/folk/pryopen/ (without the filename at the end).

    > I must use /folk/pryopen/index.html, in any file,
    > at any level, and it will work just fine.


    Or just /folk/pryopen/ to reference it more cleanly without the
    hardcoded filename.

    > I tried to use the
    > <base href="http://www.angelfire.com/folk/pryopen">
    > in the head, to shorten the relative path to:
    > /index.htm, but no dice.


    First, you should include the trailing slash:
    <base href="http://www.angelfire.com/folk/pryopen/">
    Without it, you're actually setting the base directory one level
    higher.

    Second, the relative URLs you use which are intended to be with respect
    to this base need not to start with a slash, since the leading slash
    always indicates you're starting at the root of the domain.

    With the above base href, you can link back to the home page with <a
    href="./">, which will go to the default index of the current
    directory, taking base tags into account.

    --
    Dan
    Dan, Feb 8, 2005
    #14
  15. theo

    Dan Guest

    Toby Inkster wrote:
    > theo wrote:
    >
    > > I can use: /notes/css/positioning.htm anywhere,
    > > in any file, in any folder, and it will work just fine.

    >
    > That is an absolute URL -- not a relative URL.
    >
    > A relative URL is any URL that does not match the regular expression
    > /^([A-Za-z0-9]+\:|\/)/.


    It can't be an absolute URL without a scheme (http:). URLs (or URIs in
    modern terminology) that start with slashes are a form of relative URI,
    though a different form from the ones without slashes.

    --
    Dan
    Dan, Feb 8, 2005
    #15
  16. theo

    Toby Inkster Guest

    Dan wrote:

    > URLs (or URIs in modern terminology)


    URL != URI. URL is a subset of URI.

    > that start with slashes are a form of relative URI


    Technically it's an "absolute path relative URL", but for most intents and
    purposes it behaves analogous to an abbreviated absolute URL.

    --
    Toby A Inkster BSc (Hons) ARCS
    Contact Me ~ http://tobyinkster.co.uk/contact
    Toby Inkster, Feb 8, 2005
    #16
  17. theo

    theo Guest

    > That's not a subdomain; it's in the main domain of angelfire.com,

    Cheers,
    Well, it looks like many of us may have learned a little something, that
    relative urls can be used either root relative or location relative.

    The root relative is my choice:

    1. In most cases, with www.domain.com, it allows me to move the entire site,
    without having to change a thing.

    2. I can use the same root relative url in any file, in any folder, just
    saves a lot of work, and thinking.

    Thanks All,
    cc
    theo, Feb 9, 2005
    #17
  18. theo

    theo Guest

    http://site-root.com/family/picnic/menu.html (absolute link)

    /family/picnic/menu.html
    (relative to the root, works anywhere within the site,
    any folder, any level)

    Dreamweaver does it this way, when selected, it makes
    all template generated pages' links uniform & easily
    moveable.

    cc
    theo, Feb 9, 2005
    #18
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Flip

    relative vs absolute URLs?

    Flip, Nov 24, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    438
  2. Kyle James Matthews

    Relative vs. absolute URLs

    Kyle James Matthews, May 11, 2004, in forum: HTML
    Replies:
    3
    Views:
    598
  3. Nathan Sokalski

    Converting Relative URLs into Absolute URLs

    Nathan Sokalski, Aug 11, 2008, in forum: ASP .Net
    Replies:
    1
    Views:
    731
    Sriram Srivatsan
    Aug 12, 2008
  4. Rudi Ahlers
    Replies:
    11
    Views:
    791
    Aaron Bertrand [MVP]
    Apr 11, 2004
  5. Nick Woolley

    Converting relative URLs to absolute?

    Nick Woolley, Jun 30, 2005, in forum: Ruby
    Replies:
    1
    Views:
    173
    Eric Hodel
    Jun 30, 2005
Loading...

Share This Page