Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Oct 2008
    Posts
    185
    Thanks
    12
    Thanked 0 Times in 0 Posts

    RESOLVED 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
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,665
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    A path with a slash in the beginning isn’t relative, it’s absolute because the slash in the beginning means “start looking for the file(s) from the document root.” The only relative thing about this is that it’s server independent.

    A true relative path would be relative to the current document. If all pages are stored in the root directory writing “index.html” would suffice. But if you have different directories you’d need to write for example “../index.html” which means “go up one level and look for index.html”. This is a significant difference to the method first mentioned.

    With slash in the beginning browser looks from very top while without slash it looks from (relative to the) current document.

  • #3
    Regular Coder
    Join Date
    Oct 2008
    Posts
    185
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Thank you for your reply. I think I understand...

    But "../help" is different from writing "/help", isn't it? I've been writing out my paths without the 2 dots.

    So if I'm understanding you correctly, "../help" goes up one level (meaning, that it looks for the referenced file in the next highest directory from the current directory) while "/help" starts searching from the very top... correct?

  • #4
    Regular Coder
    Join Date
    Oct 2008
    Posts
    185
    Thanks
    12
    Thanked 0 Times in 0 Posts
    And another question, when referencing web pages in your relative or absolute paths, is it necessary to place ".html" at the end?

    Such as "../help.html" ... ?

  • #5
    Senior Coder
    Join Date
    Oct 2005
    Posts
    1,340
    Thanks
    0
    Thanked 61 Times in 60 Posts
    Quote Originally Posted by jihanemo View Post
    So if I'm understanding you correctly, "../help" goes up one level (meaning, that it looks for the referenced file in the next highest directory from the current directory) while "/help" starts searching from the very top... correct?
    Yes and yes.

  • #6
    Regular Coder
    Join Date
    Oct 2008
    Posts
    185
    Thanks
    12
    Thanked 0 Times in 0 Posts
    Great. Thank you!

  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,665
    Thanks
    6
    Thanked 1,006 Times in 979 Posts
    Quote Originally Posted by jihanemo View Post
    And another question, when referencing web pages in your relative or absolute paths, is it necessary to place ".html" at the end?

    Such as "../help.html" ... ?
    Yes, you need to put the extension because you can have a help.html and a help.php file with different contents (not that this is good practice but theoretically it’s possible) and how would the browser know what file to look for.

    However, there are methods to circumvent this “restriction”. Search for “pretty URLs” or “htaccess URL rewriting” or something like that.


  •  

    Posting Permissions

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