Links to files relative to the site root  | |
April 2nd, 2003, 02:52 PM
|
#1 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Savannah, GA
Posts: 1,752
| 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... |
| |
April 2nd, 2003, 03:02 PM
|
#2 (permalink)
| | Ultimate Member
Join Date: Oct 2001
Posts: 1,542
| |
| |
April 2nd, 2003, 03:09 PM
|
#3 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Savannah, GA
Posts: 1,752
|
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
|
| |
April 2nd, 2003, 03:21 PM
|
#4 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Savannah, GA
Posts: 1,752
|
Is there a way I can get away without putting in "www.whatever.com" and just get to the root folder of the server? |
| |
April 2nd, 2003, 03:24 PM
|
#5 (permalink)
| | Ultimate Member
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) |
| |
April 2nd, 2003, 03:49 PM
|
#6 (permalink)
| | Ultimate Member
Join Date: Oct 2001 Location: Savannah, GA
Posts: 1,752
|
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? |
| |
March 23rd, 2009, 01:54 PM
|
#7 (permalink)
| | Junior Member
Join Date: Mar 2009
Posts: 7
|
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($pattern, substr($string, $i, 1)))
$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.
|
| |
March 23rd, 2009, 01:54 PM
|
#8 (permalink)
| | Junior Member
Join Date: Mar 2009
Posts: 7
|
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.
|
| | | Thread Tools | Search this Thread | | | | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |