Relative/Absolute URLS

T

theo

Cheers,
I am somewhat confused over using relative paths, due to the fact that
different web-servers seem to act differently. Is there a catch-all
solution for relative paths? One host, if I use /index.htm or
/tools/search.htm, it will always forever work. Another host, can't find
graphics or folders. Another host, I always use ../index.htm or
.../tools/search.htm, and it always works like a charm.
It's driving me mad, new hosted domain today, which I haven't figured out
yet. One minute it's fine, resolved, and next time it can't find a thing.
HELP? Any relative paths are supposedly linked from the root folder. How
do I determine the root folder? Does anyone know of any good tutorials on
this particular nightmare?

cc
 
R

Roy Schestowitz

theo said:
Cheers,
I am somewhat confused over using relative paths, due to the fact that
different web-servers seem to act differently. Is there a catch-all
solution for relative paths? One host, if I use /index.htm or
/tools/search.htm, it will always forever work. Another host, can't find
graphics or folders. Another host, I always use ../index.htm or
../tools/search.htm, and it always works like a charm.
It's driving me mad, new hosted domain today, which I haven't figured out
yet. One minute it's fine, resolved, and next time it can't find a thing.
HELP? Any relative paths are supposedly linked from the root folder. How
do I determine the root folder? Does anyone know of any good tutorials on
this particular nightmare?

cc

There is a similar issue with upper-case/lower-case where the obvious
solution is to care for case-sensitivity. This means that extra caution is
needed and on a Window$ host there is no way of testing this for guaranteed
robustness.

As for paths, you should always be fine with "../tools/search.htm", for
example. This should always be relative to the current page. Having said
that, some crawlers are too (shall I say?) stupid to handle this properly.
Also, this induces a big cost when moving pages around and changing
levelling. It's a clear case of trade-offs. The best you can do is stick to
one host and not migrate too much.

Roy
 
T

Toby Inkster

theo said:
I am somewhat confused over using relative paths, due to the fact that
different web-servers seem to act differently.

No they don't. Relative URLs aren't even interpreted by the server --
they're interpreted by the browser. The browser *always* requests
absolute URLs from the server. The web server *only* has to deal with
absolute URLs.
One host, if I use /index.htm or /tools/search.htm, it will always
forever work. Another host, can't find graphics or folders. Another
host, I always use ../index.htm or ../tools/search.htm, and it always
works like a charm.

Then I'm guessing you do not correctly understand the difference between
"../index.htm" and "/index.htm". The first means "find 'index.htm' in the
directory above the current directory. The latter means "fine 'index.htm'
in the top directory". If you are in the "first layer" of subdirectories,
both will mean the same. Otherwise, they'll each do different things.
 
T

theo

HELP? Any relative paths are supposedly linked from the root folder.
How
As for paths, you should always be fine with "../tools/search.htm", for
example. This should always be relative to the current page. Having said
that, some crawlers are too (shall I say?) stupid to handle this properly.
Also, this induces a big cost when moving pages around and changing
levelling. It's a clear case of trade-offs. The best you can do is stick to
one host and not migrate too much.

Roy


Roy,
Thanks for your input. I use templates, and so I can't program each page,
need a relative url to the entire site, to the "parent directory". The
.../tools/search.htm works well most of the time. Dreamweaver usually does it
this way, but lately I've run into sites which don't. Either linux or win
is the problem, or possibly an issue with quote, "parent directory". I
haven't figured that out yet, and am wondering how to tackle this issue.
Thanks,
cc
 
T

theo

in the top directory". If you are in the "first layer" of subdirectories,
both will mean the same. Otherwise, they'll each do different things.


Toby,
Directnic hosts 4 of my domains, and / whatever always strips you down to
the parent directory. /index.htm, from any page at any level, will take you
to the first level index file. I know, it's supposed that the browser
handles all of this, but why does this only work with directnic?

I've beat myself down, made a page with 50 links, put it in 4 levels, with
.../ with / with ../../ trying to find out how to make other sites work the
same. The slashes and dots do strip you down, but not to the point where
the same relative link is understood at all levels.

Leaves me in the position that you speak of, that each link on every page,
has to be specific and relative, not to the parent level, but to the present
level.

Directnic: Maybe I should be asking them...

thanks....
cc
 
T

theo

Then I'm guessing you do not correctly understand the difference between
"../index.htm" and "/index.htm". The first means "find 'index.htm' in the
directory above the current directory. The latter means "fine 'index.htm'
in the top directory". If you are in the "first layer" of subdirectories,
both will mean the same. Otherwise, they'll each do different things.

Cheers,
I finally figured the situation. My host, if you enter any bad path,
you'll
be instantly brought to the index.htm The root directory only has one file,
which is the index.htm, and the entire site only has two levels in directory
structure. This explains my scenerio, that /anything/anything.htm or
/anything.htm will always get you there. In this case, it's the server which
gets you there, and not the browser, but due to the structure of the site.

I tried http://tobyinkster.co.uk/go.htm and it brings me to a 404 page.
With
my site, you'll never ever see a 404, but the index instead.

Thanks,
cc
 
T

theo

Dan said:
Some relevant info:

URLs (URIs), relative and absolute:
http://webtips.dan.info/url.html

Directories and Default Index Files:
http://webtips.dan.info/subdir.html

+++ A URL with a slash at the start, like "/dir1/dir2/stuff.html",
+++ references a page at a path starting from the root of the server.
+++ To be more precise, it starts at the root of the domain name you're in.

Thanks Dan,

The path relative to server root was what I was looking for,
which I'm not sure that Toby mentioned. Wasn't interested
in climbing up or down notches in the tree.

I'm still having problems with one domain, actually a sub-domain,
where the root-relative relative paths don't seem to work. I haven't
figured
the root, quite yet.

Paste follows:
__________________________________
Thank you for using the directNIC.com Trouble Ticket System. The following
response is from a qualified directNIC customer support team member:

Date: 02/07/05 01:36pm
From: mbrunson

directNIC's links should be the same as any other webserver, since
it's more a function of the client software. There are several ways
to refer to a page on your site. Let's say you're on the page:
http://example.com/family/picnic/photo.html And want to link to a page:
http://example.com/fun/car/engine.html You could add the link in a
couple ways, such as:
http://example.com/fun/car/engine.html (absolute link)
/fun/car/engine.html (relative to the root)
.../../fun/car/engine.html (relative to the page you are on)

If you wanted to link to a page in the same directory, let's say:
http://example.com/family/picnic/menu.html You could do this with the
following:
http://example.com/family/picnic/menu.html (absolute link)
/family/picnic/menu.html (relative to the root)
../menu.html (relative the the current page)
menu.html (relative the the current page the "./" is inferred)

paste ends
+++++++++++++++++++++++++++

Thanks,
cc
 
D

Dan

theo said:
I'm still having problems with one domain, actually a sub-domain,
where the root-relative relative paths don't seem to work. I haven't
figured
the root, quite yet.

I'm not sure I understand your problem. A subdomain is just like any
other domain, except it's third-level (or more) instead of
second-level, so that if you have the domain bar.net, you can use
subdomains like foo.bar.net. The principles behind how they work on
the Web are the same as for "regular" domains.

If the server is configured so that foo.bar.net serves the main index
file out of some directory on the server (maybe a different one from
where the main domain bar.net is served out of), then that directory is
the "root" as far as URLs in that subdomain are concerned.
 
T

theo

Dan,
I did finally find the server root. Now, I can put
the same exact relative url in all html files, at any level,
and they'll work. No moving up and down BS,
having to edit every single file at every level,
relative to present location.

For:
http://domainroot.com/notes/css/positioning.htm

I can use: /notes/css/positioning.htm anywhere,
in any file, in any folder, and it will work just fine.

I have an angelfire subdomain from hell spare site, which is:
http://angelfire.com/folk/pryopen/index.html

I must use /folk/pryopen/index.html, in any file,
at any level, and it will work just fine.

I tried to use the
<base href="http://www.angelfire.com/folk/pryopen">
in the head, to shorten the relative path to:
/index.htm, but no dice.

cc
 
T

Toby Inkster

theo said:
I did finally find the server root. Now, I can put
the same exact relative url in all html files, at any level, [...]
I can use: /notes/css/positioning.htm anywhere,
in any file, in any folder, and it will work just fine.

That is an absolute URL -- not a relative URL.

A relative URL is any URL that does not match the regular expression
/^([A-Za-z0-9]+\:|\/)/.
 
D

Dan

theo said:
I did finally find the server root. Now, I can put
the same exact relative url in all html files, at any level,
and they'll work. No moving up and down BS,
having to edit every single file at every level,
relative to present location.

On the other hand, the relative "moving up and down BS" URLs work
better when you browse the pages on your local hard disk before
uploading them to a server, so some prefer that syntax on this account.
I have an angelfire subdomain from hell spare site, which is:
http://angelfire.com/folk/pryopen/index.html

That's not a subdomain; it's in the main domain of angelfire.com,
though in a (two-level-deep) subdirectory of its main server root. A
subdomain would be pryopen.angelfire.com. And since index.html is the
server default index file, you can cite the URL more short-and-sweet as
http://angelfire.com/folk/pryopen/ (without the filename at the end).
I must use /folk/pryopen/index.html, in any file,
at any level, and it will work just fine.

Or just /folk/pryopen/ to reference it more cleanly without the
hardcoded filename.
I tried to use the
<base href="http://www.angelfire.com/folk/pryopen">
in the head, to shorten the relative path to:
/index.htm, but no dice.

First, you should include the trailing slash:
<base href="http://www.angelfire.com/folk/pryopen/">
Without it, you're actually setting the base directory one level
higher.

Second, the relative URLs you use which are intended to be with respect
to this base need not to start with a slash, since the leading slash
always indicates you're starting at the root of the domain.

With the above base href, you can link back to the home page with <a
href="./">, which will go to the default index of the current
directory, taking base tags into account.
 
D

Dan

Toby said:
theo said:
I can use: /notes/css/positioning.htm anywhere,
in any file, in any folder, and it will work just fine.

That is an absolute URL -- not a relative URL.

A relative URL is any URL that does not match the regular expression
/^([A-Za-z0-9]+\:|\/)/.

It can't be an absolute URL without a scheme (http:). URLs (or URIs in
modern terminology) that start with slashes are a form of relative URI,
though a different form from the ones without slashes.
 
T

Toby Inkster

Dan said:
URLs (or URIs in modern terminology)

URL != URI. URL is a subset of URI.
that start with slashes are a form of relative URI

Technically it's an "absolute path relative URL", but for most intents and
purposes it behaves analogous to an abbreviated absolute URL.
 
T

theo

That's not a subdomain; it's in the main domain of angelfire.com,

Cheers,
Well, it looks like many of us may have learned a little something, that
relative urls can be used either root relative or location relative.

The root relative is my choice:

1. In most cases, with www.domain.com, it allows me to move the entire site,
without having to change a thing.

2. I can use the same root relative url in any file, in any folder, just
saves a lot of work, and thinking.

Thanks All,
cc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top