By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,650 Members | 1,778 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,650 IT Pros & Developers. It's quick & easy.

what is the effect of leading slash in URL?

P: n/a
I have in my page:

<base href="http://www.simple-nude.com/">

and later want to direct a visitor to, say,

http://www.simple-nude.com/today/hippie-goddess/15b.jpg

It seems that the link text can read as either of:

<a href="/today/hippie-goddess/15b.jpg" or
<a href="today/hippie-goddess/15b.jpg">

First form contains a leading slash, second form does not.

Are these two forms perfectly interchangeable? Do they always have
exactly the same effect under all conditions? If not, then what is the
effective difference between the two forms?

Thanks!

-- fredo

Sep 15 '06 #1
Share this Question
Share on Google+
15 Replies


P: n/a
fredo wrote:

[snip]
<base href="http://www.simple-nude.com/">
[snip]
<a href="/today/hippie-goddess/15b.jpg" or
<a href="today/hippie-goddess/15b.jpg">
[snip]
Are these two forms perfectly interchangeable?
Not necessarily. It depends on the base URL.
Do they always have exactly the same effect under all conditions?
No.
If not, then what is the effective difference between the two forms?
A leading slash in a path refers to the root directory. That is, with a
base URL of

http://www.example.com/foo/bar

the URL

/baz

is resolved as:

http://www.example.com/baz

In contrast, the URL

baz

would resolve to:

http://www.example.com/foo/baz
The base URL you've set explicitly using the base element makes either
form more-or-less interchangeable, but only because of the URL you chose.

Mike
Sep 15 '06 #2

P: n/a

Michael Winter wrote:
A leading slash in a path refers to the root directory. That is, with a
base URL of

http://www.example.com/foo/bar

the URL

/baz

is resolved as:

http://www.example.com/baz

In contrast, the URL

baz

would resolve to:

http://www.example.com/foo/baz
I'm still confused. Would not the second example refer to:

http://www.example.com/foo/bar/baz

given, as in your example, the base URL:

http://www.example.com/foo/bar

Thanks, Mike.

-- fredo

Sep 15 '06 #3

P: n/a
fredo wrote:
Michael Winter wrote:
[snip]
>In contrast, the URL

baz

would resolve to:

http://www.example.com/foo/baz

I'm still confused. Would not the second example refer to:

http://www.example.com/foo/bar/baz

given, as in your example, the base URL:

http://www.example.com/foo/bar
No, because bar is a resource (a file, for example) not a directory (I'd
have added a trailing slash if I'd meant the latter).

Perhaps if I'd have written:

http://www.example.com/foo/bar.html

as the base URL, and

baz.html

as the relative address to be resolved, it would have been more clear that

http://www.example.com/foo/baz.html

would have been the result? If so, just remember that extensions mean
nothing in URLs, and that it's a good idea to use canonical URLs (paths
to a directory should always end with a slash, for example).

Mike
Sep 15 '06 #4

P: n/a
[not disagreeing, just clarifying :-)]

Michael Winter:
A leading slash in a path refers to the root directory.
I think you are blurring the distinction between filenames and URL
paths. The leading slash of an absolute-path reference does not refer
to the root directory nor any other part of the filesystem, since what
a URL points to is determined by both the URL itself and a mapping
between URL and resource. The leading slash in an absolute-path
reference is relevant to the resolution of the relative reference, not
directly to the determination of what the (resolved) URL points to.

--
Jock

Sep 15 '06 #5

P: n/a
Dan

Michael Winter wrote:
No, because bar is a resource (a file, for example) not a directory (I'd
have added a trailing slash if I'd meant the latter).
Unfortunately, the bad and sloppy habit of leaving out trailing slashes
of directory references is so widespread that people don't seem to
understand this distinction any more, and get surprised and stumped
whenever the lack of the slash actually leads to distinct differences
as in the case of resolving relative addresses from base URIs.

--
Dan

Sep 15 '06 #6

P: n/a
us*********@john.dunlop.name wrote:
[not disagreeing, just clarifying :-)]

Michael Winter:
>A leading slash in a path refers to the root directory.

I think you are blurring the distinction between filenames and URL
paths.
If this was a technical discussion, I would have used different
terminology. As I doubt that the OP has read RFC 3986 or its
predecessors (something I meant to suggest), it didn't seem wise or
helpful to use the terms it defines.
The leading slash of an absolute-path reference does not refer
to the root directory nor any other part of the filesystem, ...
And I did not say that it did, but I'm not aware of a universally
accepted name. Suggestions? The phrase "document root", perhaps?

At least the word, "root", seems sensible both because path segments are
hierarchical, and (one form[1] of) a relative-path reference is labelled
"rootless" in URI grammar.

I used the word "directory" previously because, conceptually, each path
segment references a directory even if redirects and other translations
can alter what is really meant. I think that concept is useful, at least
whilst discussing the basics of the topic, as it does reflect reality
most of the time (though the "root" isn't the partition root).

[snip]

Mike
[1] The other, "noscheme", isn't quite so useful for deriving a
name.
Sep 15 '06 #7

P: n/a
fredo wrote:
I have in my page:

<base href="http://www.simple-nude.com/">

and later want to direct a visitor to, say,

http://www.simple-nude.com/today/hippie-goddess/15b.jpg

It seems that the link text can read as either of:

<a href="/today/hippie-goddess/15b.jpg" or
<a href="today/hippie-goddess/15b.jpg">
"/x/y" means resource y in directory x in the site root. "x/y" means
resource y in directory x in the current page's directory. (The
situation changes a little, but with the same outcome, if there's a BASE
tag in the current page.) Therefore, if the current page's directory is
the site root (as is the case with the home page), then the two forms
resolve to the same thing. Otherwise, they don't.
Sep 15 '06 #8

P: n/a
Michael Winter:
I used the word "directory" previously because, conceptually, each path
segment references a directory even if redirects and other translations
can alter what is really meant.
Each path segment *can* reference a directory, yes, but equally they
need not and sometimes do not. To say that '[a] leading slash in a
path refers to the root directory' is therefore not always true, and I
think that that statement, read as a universal, blurs the useful
distinction between filenames and URL paths. Besides, why would you
bring concepts from filesystems into a discussion of URLs?
I think that concept is useful, at least whilst discussing the basics of
the topic, as it does reflect reality most of the time (though the "root"
isn't the partition root).
'I regard the mitigation of readers' distress as insufficient grounds
for the propagation of error.' (the late Jim McCawley)

--
Jock

Sep 15 '06 #9

P: n/a
us*********@john.dunlop.name wrote:
Michael Winter:
>I used the word "directory" previously because, conceptually, each path
segment references a directory even if redirects and other translations
can alter what is really meant.

Each path segment *can* reference a directory, yes, but equally they
need not and sometimes do not. To say that '[a] leading slash in a
path refers to the root directory' is therefore not always true, and I
think that that statement, read as a universal, blurs the useful
distinction between filenames and URL paths. Besides, why would you
bring concepts from filesystems into a discussion of URLs?
"Directory" isn't a concept from file systems. It's a generic concept
that existed long before there was such a thing as a computer file. Its
use in the area of file systems is only one specific application of the
concept.

Since so many terms used in the field of computing were existing terms
applied to new but analogous concepts, an objection to the same kind of
reuse now seems ironic.

The preceding is just general commentary. Although I use "directory"
myself to name the theoretical construct represented by a path segment,
I can appreciate the fact that the analogy relies on the notion of
containment, and it's true that a segmented path doesn't necessarily
represent containment. For example, Microsoft's knowledge base articles
used to have URLs with something like a/bc/def in them to represent KB
article number abcdef. I don't know why they did that--probably having
something to do with scalability--but certainly there was no implication
that KB articles are grouped into sets of a hundred thousand each, with
each of those groups divided further into discrete sets of a thousand
articles each.
>
>I think that concept is useful, at least whilst discussing the basics of
the topic, as it does reflect reality most of the time (though the "root"
isn't the partition root).

'I regard the mitigation of readers' distress as insufficient grounds
for the propagation of error.' (the late Jim McCawley)
Sep 15 '06 #10

P: n/a
Harlan Messinger:
"Directory" isn't a concept from file systems. It's a generic concept
that existed long before there was such a thing as a computer file. Its
use in the area of file systems is only one specific application of the
concept.

Since so many terms used in the field of computing were existing terms
applied to new but analogous concepts, an objection to the same kind of
reuse now seems ironic.
My objection is to the statement, whether or not anyone actually meant
it, that a leading slash in a URL path refers to a particular directory
in a filesystem.

I am not objecting to the use of the term itself.

--
Jock

Sep 15 '06 #11

P: n/a
Dan

us*********@john.dunlop.name wrote:
My objection is to the statement, whether or not anyone actually meant
it, that a leading slash in a URL path refers to a particular directory
in a filesystem.
One way of thinking of URLs (at least within schemes such as HTTP that
use hierarchical paths) is as defining a sort of "virtual filesystem"
with directories and a root, and that is what is being discussed
whenever somebody refers to the URL as having these things. This may
or may not correspond to an actual physical filesystem (and the "root"
of the document tree is probably not the physical root of the
filesystem even if there is one).

--
Dan

Sep 15 '06 #12

P: n/a
Dan:
One way of thinking of URLs (at least within schemes such as HTTP that
use hierarchical paths) is as defining a sort of "virtual filesystem"
with directories and a root, and that is what is being discussed
whenever somebody refers to the URL as having these things.
It isn't always easy to tell if someone who uses 'directory' in
relation to a URL is talking about the URL string itself or is
confusing the URL path with the filesystem.

My point, again, was that saying that leading slashes refer to
particular, concrete filesystem directories conflates URL path segments
with filesystem directories. I think it is useful to keep this
distinction, because if indeed there is a filesystem the mapping from
URL path to filesystem needn't be 1-to-1.

--
Jock

Sep 15 '06 #13

P: n/a
"fredo" <fr***@simple-nude.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
I have in my page:

<base href="http://www.simple-nude.com/">

and later want to direct a visitor to, say,

http://www.simple-nude.com/today/hippie-goddess/15b.jpg

It seems that the link text can read as either of:

<a href="/today/hippie-goddess/15b.jpg" or
<a href="today/hippie-goddess/15b.jpg">

First form contains a leading slash, second form does not.

Are these two forms perfectly interchangeable? Do they always have
exactly the same effect under all conditions? If not, then what is the
effective difference between the two forms?

Thanks!
Leading / = Absolute (This is how to get to the file from "root")
From: www.mysite.com/my/example/works
Link: /like/this.html
Makes: www.mysite.com/like/this.html

No leading / = Relative (This is how to get to the file from this "folder")
From: www.mysite.com/my/example/works
Link: like/this.html
Makes: www.mysite.com/my/example/works/like/this.html
Sep 15 '06 #14

P: n/a
"Trammel" <Me@Server.comwrote in message
news:Hk**************@fe1.news.blueyonder.co.uk...
"fredo" <fr***@simple-nude.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
I have in my page:

<base href="http://www.simple-nude.com/">

and later want to direct a visitor to, say,

http://www.simple-nude.com/today/hippie-goddess/15b.jpg

It seems that the link text can read as either of:

<a href="/today/hippie-goddess/15b.jpg" or
<a href="today/hippie-goddess/15b.jpg">

First form contains a leading slash, second form does not.

Are these two forms perfectly interchangeable? Do they always have
exactly the same effect under all conditions? If not, then what is the
effective difference between the two forms?

Thanks!

Leading / = Absolute (This is how to get to the file from "root")
From: www.mysite.com/my/example/works
Link: /like/this.html
Makes: www.mysite.com/like/this.html

No leading / = Relative (This is how to get to the file from this
"folder")
From: www.mysite.com/my/example/works
Link: like/this.html
Makes: www.mysite.com/my/example/works/like/this.html
Oops... before anyone else corrects me... by file, I mean whatever the
resource is (May be images, generated code, etc)
Sep 16 '06 #15

P: n/a
"Trammel" <Me@Server.comwrote in message
news:Hk**************@fe1.news.blueyonder.co.uk...
"fredo" <fr***@simple-nude.comwrote in message
news:11**********************@d34g2000cwd.googlegr oups.com...
I have in my page:

<base href="http://www.simple-nude.com/">

and later want to direct a visitor to, say,

http://www.simple-nude.com/today/hippie-goddess/15b.jpg

It seems that the link text can read as either of:

<a href="/today/hippie-goddess/15b.jpg" or
<a href="today/hippie-goddess/15b.jpg">

First form contains a leading slash, second form does not.

Are these two forms perfectly interchangeable? Do they always have
exactly the same effect under all conditions? If not, then what is the
effective difference between the two forms?

Thanks!

Leading / = Absolute (This is how to get to the file from "root")
From: www.mysite.com/my/example/works
Link: /like/this.html
Makes: www.mysite.com/like/this.html

No leading / = Relative (This is how to get to the file from this
"folder")
From: www.mysite.com/my/example/works
Link: like/this.html
Makes: www.mysite.com/my/example/works/like/this.html
Also worth noting might be that '..' works for website URLs too
... = Go "up" a "folder"
From: www.mysite.com/my/example/works
Link: ../../like/this.html
Makes: www.mysite.com/my/like/this.html
Sep 17 '06 #16

This discussion thread is closed

Replies have been disabled for this discussion.