...

View Full Version : RESOLVED How to Reference the Home Page in a Relative Path?



jihanemo
11-28-2009, 01:29 AM
I've got it down as
"/index.html" - is that absolutely right?

And when using relative path codes, is a slash
/ 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

VIPStephan
11-28-2009, 02:11 AM
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.

jihanemo
11-28-2009, 02:24 AM
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?

jihanemo
11-28-2009, 03:01 AM
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" ... ?

drhowarddrfine
11-28-2009, 05:50 AM
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.

jihanemo
11-28-2009, 06:07 AM
Great. Thank you!

VIPStephan
11-28-2009, 03:17 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum