SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Addict
    Join Date
    Nov 2008
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to Reference the Home Page in a Relative Path?

    I've got it down as
    Code:
    "/index.html"
    - is that absolutely right?

    And when using relative path codes, is a slash
    Code:
    /
    at the beginning absolutely necessary?

    I'm finding it necessary to use relative paths just in case I change my website to a .com...

    http://americanchic.net/blank

  2. #2
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Both are relatives, absolute would be if you'd include the domain name, i.e.
    Code:
    http://americanchic.net/index.html
    - though never actually use index.html.

    the / always lets you start from root, even if you are three folder levels down. Assuming that you want are in
    Code:
    http://americanchic.net/categories/fun/vacation-france.html
    and you want to point to an image located in
    Code:
    http://americanchic.net/images/france/beach.jpg
    you'd can use
    Code:
    /images/france/beach.jpg
    however, if that image is located in
    Code:
    http://americanchic.net/categories/fun/images/beach.jpg
    then you simply point to it by
    Code:
    images/beach.jpg
    no slash at the beginning as images is a subfolder of the current folder.

    hope that makes sense
    Dan G
    Marketing Strategist & Consultant

  3. #3
    SitePoint Addict
    Join Date
    Nov 2008
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you! And what does putting 2 dots and a dash in the beginning mean? Such as
    Code:
    ../images/france/beach.jpg

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ./ means this directory
    ../ means the parent directory

  5. #5
    SitePoint Wizard bronze trophy Black Max's Avatar
    Join Date
    Apr 2007
    Posts
    4,029
    Mentioned
    12 Post(s)
    Tagged
    0 Thread(s)
    Here's how that works (and I always get fuddled about this). I've got a root directory. In that directory let's say I've got several subdirectories:
    • images
    • javascript
    • singlecol
    • css


    If I have a page in the singlecol directory that references the stylesheet in the css directory, I have to trace the path as such:

    Code HTML 4 Strict:
    <link rel="stylesheet" type="text/css" media="screen" href="../css/styles.css">

    The singlecol page is told by the path element to go up to the root directory, then back down to the css directory to find the stylesheet.

  6. #6
    SitePoint Addict
    Join Date
    Nov 2008
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you for the last 2 responses but that just confuses me a little bit more. This has become horrifying.

    How about this...

    My website is only pulling pages and images from 2 directories in the server - one directory called website_images and then the root (if that's even considered a directory at all). ALL pages are in the root and all images are in the website_graphics directory. Right now, I'm using a single slash at the beginning of the paths such as

    Code:
    /website_graphics/logo.jpg
    Code:
    /help.html
    That's the whole of it. And then there's this for home page links.

    Code:
    <a href="index.html"...>
    And the reason I'm using relative paths (at least, I thought I was) is because I plan on changing the website to a .com in the future.

    Have I served the purpose well by using the single dash (which seems an acceptable form of creating paths)?


  7. #7
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could say there are two types of relative paths, relative to where you are in the script (../../folder/something.pdf) and relative to the root (/folder/something.pdf). They are both relative as you need a start point, that is to say http://domain.com/folder/something.pdf works from your server, my computer, and the net cafe. But the others only work if you start from your server. Hence relative to your at least server, if not the directory the script is running from.

    Personally I go for / mostly. That means start from the server root (www/). But there can be issues with this. e.g. if you want to move everything to a sub folder of www (will be fine if you just switch .net to .com though).

  8. #8
    SitePoint Addict
    Join Date
    Nov 2008
    Posts
    201
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That clears it up... mostly. Thank you.

  9. #9
    doing my best to help c2uk's Avatar
    Join Date
    May 2005
    Location
    Cardiff
    Posts
    1,832
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jihanemo View Post
    Thank you for the last 2 responses but that just confuses me a little bit more. This has become horrifying.

    How about this...

    My website is only pulling pages and images from 2 directories in the server - one directory called website_images and then the root (if that's even considered a directory at all). ALL pages are in the root and all images are in the website_graphics directory. Right now, I'm using a single slash at the beginning of the paths such as

    Code:
    /website_graphics/logo.jpg
    Code:
    /help.html
    That's the whole of it. And then there's this for home page links.

    Code:
    <a href="index.html"...>
    And the reason I'm using relative paths (at least, I thought I was) is because I plan on changing the website to a .com in the future.

    Have I served the purpose well by using the single dash (which seems an acceptable form of creating paths)?

    First, as I said, never ever use index.html to point to your home page, if you want/have to use relative paths, then use a /

    If all pages are in the root, and all images are in the image folder, than you don't need the / at the beginning of all other references. Though, I strongly advice you to add a few more folders to it, i.e. what about css (and yes you should be using external css files, and it makes sense to put it into its own folder), also consider how your site is going to evolve.

    And lastly, if we're talking about links/references to material to your own site, then you normally always use relative paths - there are some exceptions but I'm not going into that detail.

    Quote Originally Posted by jihanemo View Post
    Thank you! And what does putting 2 dots and a dash in the beginning mean? Such as

    Code:
    ../images/france/beach.jpg
    Imagine, your are looking at
    Code:
    http://americanchic.net/categories/fun/vacation-france.html
    and have that reference in the code, the browser would look for beach.jpg here:
    Code:
    http://americanchic.net/categories/images/france/beach.jpg
    i.e. one folder up (the direct parent) has the images folder with another folder france in it. ../../ would mean go up two folders and look there, and so forth

    Personally, I agree with hash and wouldn't ever use this system but the relative from root.
    Dan G
    Marketing Strategist & Consultant


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •