tags:

views:

271

answers:

3
<img src="images/logo.gif" />

is equivalent to

<img src="./images/logo.gif" />

But

<img src="/images/logo.gif" />

is different.

Where is the third item looking for logo.gif?

+9  A: 

The third one is looking relative to the root of the site, so if you were on a page at:

http://entrian.com/somewhere/page.html

it would look in:

http://entrian.com/images/logo.gif

ignoring the somewhere piece of the page's address.

RichieHindle
What if the .html file is on your local disk though?
bobobobo
then substitute entrian.com for http://localhost/
jskulski
On the local disk, it goes back to the root of the drive; E:\somewhere\page.html -> E:\images\logo.gif on windows, /home/me/somewhere/page.html -> /images/logo.gif on unix.
Stobor
@bobobobo: It will look for the file at /images/logo.gif on your local machine. On Unix that'll be fine; on Windows it might work depending on your browser (it will work in IE, but not in Firefox). Depending on the browser, you might have to explicitly say href="file://c:/images/logo.gif". If you're writing the page for the web, but testing on your local machine, you should install a web server and test under that - loading it directly from the file system is not a realistic test of how the page will load under a real web server.
RichieHindle
+3  A: 

images/logo.gif

It's relative and means: Go to a folder called images and then get the resource logo.gif

./images/logo.gif

It's relative and means: From the current folder (the dot means this) go to a folder called images and then get the resource logo.gif

As you can see the first two mean the same, finally the last one

/images/logo.gif

It's absolute and means: From the root of the web server or the file system or whatever (the slash means this) go to a folder called images and then get the resource logo.gif

victor hugo
But not AS absolute as http://www.example.com/images/logo.gif would be. I like to think of it as relatively absolute :)
Bobby Jack
@Bobby Jack Haha You are right!
victor hugo
In what case would they differ? say if you were using a mod_rewrite or sub directory?
jskulski
oops - my comment above should have the full protocol at the beginning - damn autolinking! They would differ if you moved from one domain (or sub-domain) to another; not a common occurrence, but there's still an air of 'relativity' about /images.
Bobby Jack
A: 

In the document root. The first two are relative paths, while the last is an absolute path.