home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Ask a Tech Support Question (free)!

Links to files relative to the site root

Reply
Get bargains at  »  Dealighted.com
 
Thread Tools Search this Thread
Currently Active Users: 2870
Discussions: 200,968, Posts: 2,379,688, Members: 246,333
Old April 2nd, 2003, 02:52 PM   Digg it!   #1 (permalink)
Ultimate Member
 
Emc2's Avatar
 
Join Date: Oct 2001
Location: Savannah, GA
Posts: 1,752
Send a message via AIM to Emc2
Links to files relative to the site root

I want to setup a javascript menu, and have links to numerous files within folders. Every page is setup in Dreamweaver from a Template. Whenever I change the Template in Dreamweaver, it updates every page that's attached to it.

The template contains the necessary info for the menus. However, let's say I go, from the site root, into a folder, like
(site root)/(folder):
courts/counties

Every page is still linked to the template
courts/Templates/base.dwt

the templates are designed in Dreamweaver to go to links relative to the current document. Say you're on the page courts/counties/dade.html, and need to go to Chandler county's webpage (same folder), then the link would be "chandler.htm".

Let's say you wanted to go back up a folder, to the index page...the link would be "../index.html"

How could I instead get the link to point to the root of the site and then go from there, instead of having to "go up" a level? This will great alleviate the problems I'm having, which are rather complex to describe.

I know that "./file.html" is the current folder "../file.html" is one folder up...
Emc2 is offline   Reply With Quote
Old April 2nd, 2003, 03:02 PM     #2 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
/courts/index.html

A / at the beginning of a link references the base URI of a page.

By default the base URI is the 'network location' e.g. www.somesite.com; however by using a BASE tag in the HEAD section the author can specify another base URI.

http://www.w3.org/TR/html401/struct/links.html#h-12.4
http://www.ietf.org/rfc/rfc1808.txt
strangerstill is offline   Reply With Quote
Old April 2nd, 2003, 03:09 PM     #3 (permalink)
Ultimate Member
 
Emc2's Avatar
 
Join Date: Oct 2001
Location: Savannah, GA
Posts: 1,752
Send a message via AIM to Emc2
So essentially, just put BASE = (site root) at the top, then make any link in any folder on any page point relative to that?
__________________
My R&D machine:

AMD 2100+ @ 2700+
Asus A7N8X-E
1GB Kingston PC333
2xWD 74GB Raptor's in SATA RAID
ATI 9700Pro w/ Zalman Heat Pipe
Emc2 is offline   Reply With Quote
Old April 2nd, 2003, 03:21 PM     #4 (permalink)
Ultimate Member
 
Emc2's Avatar
 
Join Date: Oct 2001
Location: Savannah, GA
Posts: 1,752
Send a message via AIM to Emc2
Is there a way I can get away without putting in "www.whatever.com" and just get to the root folder of the server?
Emc2 is offline   Reply With Quote
Old April 2nd, 2003, 03:24 PM     #5 (permalink)
Ultimate Member
 
strangerstill's Avatar
 
Join Date: Oct 2001
Posts: 1,542
Yeah, that's what a link starting "/" does - on the page www.whatever.com/parth/to/page.html the link /another/page.html evaulates (in the browser) to www.whatever.com/another/page.html

The BASE tag is a bit of a non sequitur, most of the time you won't need it (it's useful for cached pages - the Google cache uses the BASE tag so that links in a cached page point to the actual site not to the Google site)
strangerstill is offline   Reply With Quote
Old April 2nd, 2003, 03:49 PM     #6 (permalink)
Ultimate Member
 
Emc2's Avatar
 
Join Date: Oct 2001
Location: Savannah, GA
Posts: 1,752
Send a message via AIM to Emc2
It's turning out that, without the BASE tag:

say I'm on the page "root/folder/page.html"

A link to "/page2.html" links to "root/folder/page2.html" and not "root/page2.html"

Is this how it's supposed to work?
Emc2 is offline   Reply With Quote
Old March 23rd, 2009, 01:54 PM     #7 (permalink)
Junior Member
 
Join Date: Mar 2009
Posts: 7
Site root

I've searched around and haven't found any way to locate the root folder (because I can't use the <base>-tag because of the structure of the site), so I got tired of searching and made a small php function instead. Actually I made 2 because I had to use another handy thing in it.

PHP Code:
 // Since I like creating my own functions, here's an equivalent of preg_match:
function numCharMatches($pattern$string)
{
    
$count 0;

    for (
$i 0$i strlen($string); $i++)
        if (
eregi($patternsubstr($string$i1)))
            
$count++;

    return 
$count;
}

 
// And here's the actual function
function locateRoot()
{
    
$matches numCharMatches("/"$_SERVER['PHP_SELF']); // Can be replaced with preg_match. Just not as hardcore.
    
$dir "";

    for (
$i 1$i $matches$i++)
        
$dir .= "../";

    return 
$dir;

Edit:

Oh, so the way to use this would be:
PHP Code:
<a href="<? echo locateRoot(); ?>courts/counties">courts/counties</a>

Last edited by Little-Burrito : March 23rd, 2009 at 01:58 PM.
Little-Burrito is offline   Reply With Quote
Old March 23rd, 2009, 01:54 PM     #8 (permalink)
Junior Member
 
Join Date: Mar 2009
Posts: 7
Oh...

I just realized this thread is six years old. That's what happens when you google.

Last edited by Little-Burrito : March 23rd, 2009 at 02:00 PM.
Little-Burrito is offline   Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Most Active Discussions
Is It Just Me? (3030)
Forty-six years ago today (12)
Breaking: San Diego ACORN Document .. (5)
Laptop with wireless problem. (12)
Wireless Televisions. (12)
CPU fan stops spinning randomly (11)
Regular Build (11)
windows vista security holes (16)
Internet Lost (5)
windows 7 problem (7)
Is the PSU I received dead? (13)
Point and Shoot Camera Suggestions. (6)
radeon x850xt platinum & shader.. (6)
HIS HD5770 graphic card question (15)
Recent Discussions
Help getting around port 80 for camer.. (5)
Skillsoft Network+ Study Software Que.. (10)
Browsers wont load websites (3)
Nvidia GTX 260 problem (2)
windows vista security holes (16)
Delete an OS (8)
help me pls laptop just stopped worki.. (0)
Open With ..... Win7 (3)
Laptop with wireless problem. (12)
Internet Lost (5)
virus blocking exe. files (1)
Point and Shoot Camera Suggestions. (6)
CPU fan stops spinning randomly (11)
Modern Warfare 2: Who Bought It? (65)
Is the PSU I received dead? (13)
Print spooler problem (16)
Kingston Bluetooth Dongle Driver (1)
Multiple Restarts Required at Boot (3)
webcam (0)
upgrade for hp a6101 (0)
tv not turn on-makes clicking sound (2)
EVGA 9800 gtx help with finding a goo.. (11)
Regular Build (11)
Help with onclick and buttons (0)
Virus advise (8)


All times are GMT -4. The time now is 05:05 PM.
TechIMO Copyright 2009 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28