Click to See Complete Forum and Search --> : Domain self-referencing in URL


Vic
08-23-2005, 12:28 AM
I am trying to make a URL reference in a one page that uses the same domain, but points to another page in a different directory.

For example, I have a page:
http://mydomain/directory1/index.htm

In the index.htm I want to create a URL that points to the same domain (http://mydomain/) but a different directory & page. For example:
http://mydomain/directory2/anotherpage.htm

Problem is, I don't want to statically code in "mydomain", as the page can be moved around between domains. Is there any way to reference page's "own" domain without having to use javascript or ASP?

NogDog
08-23-2005, 12:52 AM
You could use the <base> element (http://www.w3.org/TR/html4/struct/links.html#h-12.4) in your <head> section to establish the base directory from which other relative urls will be calculated.

Vic
08-23-2005, 01:16 AM
<base> is a good override, but your link has pointed me in the right direction to find that ".." is a keyword for self (if <base> is not specified. Hence:

../directory2/anotherpage.htm

will achieve the exact result I was looking for. Thanks!

Vic
08-23-2005, 01:42 AM
I spoke too soon: "../" only shifts one directory back, it does not reference the base domain. Any thoughts how I could address the base domain in a relative way (i.e. irrespective of how many levels of directories the calling page is in)?

For example, consider two pages:
http://mydomain/dir1/page.htm
http://mydomain/dir1/dir2/dir3/page.htm

Is there any way to reference, eg:
http://mydomain/test/foo.htm

Such that I don't have to count the direcotry depth in the page (otherwise I would have to reference ../test/foo.htm for the first example and ../../../test/foo.htm for the second)?