Forum Moderators: phranque

Message Too Old, No Replies

<!--#include virtual=""--> Is this how it is supposed to work?

links not linking properly

         

nigassma

12:33 am on Aug 31, 2005 (gmt 0)

10+ Year Member



This may not be the correct forum (if it isn't can it be moved to the correct one please)

Here goes... :)

I have a site running on an Apache 1.33 server, and am using a SSI to include the main navigation. My include looks like this...


<!--#include virtual="/nav.htm"-->

It is placed accross the entire site, and works great until you get to any page that is not the homepage.

The HTML looks like this in 'nav.htm'...


<ul id="topnav">
<li><a href="/about/index.htm" class="p7PMtrg">About</a>
<ul>
<li><a href="/about_harker/index.htm">Overview</a></li>
<li><a href="/" class="p7PMtrg">Our Campuses</a>
<ul>
<li><a href="/about_harker/index.htm">Lower School</a></li>
<li><a href="/about_harker/welcome.htm">Middle School</a></li>
<li><a href="/about_harker/philosophy.htm">Upper School</a></li>
</ul>
</li>
<li><a href="/about/welcome.htm">Welcome</a></li>
<li><a href="/about/philosophy.htm">Philosophy</a></li>
<li><a href="/history/index.htm">History</a></li>
<li><a href="/achievements/index.htm">Achievements</a></li>
<li><a href="/about/careers.htm">Careers</a></li>
<li><a href="/media/index.htm">Media</a></li>
</ul>
</li>
</ul>

The problem lies in the links themselves, I think... Somehow when you get to the subpages the links in 'nav.htm' become relative to the directory they are in. So if I cruise to the page "about/index.htm" the nav menu links to the rest of the site now start with "about/" as the root folder instead of "/". How can I fix this?

jdMorgan

1:29 am on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You should not be having a problem, since all links are preceded by "/". That makes then relative to the root of your site, and not relative to the current page location.

Try specifying a canonical URL (http://www.example.com/campus.html) for one of those pages, then re-test and see if anything changes.

If this is new code, be sure you flush your browser cache before testing any changes.

If neither of these helps, then do a view-page source in your browser. Since it is the browser that resolves all non-canonical links, you should see the problem in the browser's copy of the code.

Jim

nigassma

4:48 pm on Aug 31, 2005 (gmt 0)

10+ Year Member



When I viewed the source all the links don't have the preceeding "../" that is necessary to make the links start from the root. They look just as they do in the main root folder: "/about/about.htm". Not as they should: "../about/about.htm"

nigassma

6:02 pm on Aug 31, 2005 (gmt 0)

10+ Year Member



putting in the http://www.example.com address before the destination works. What makes the difference?

[edited by: jatar_k at 6:48 pm (utc) on Aug. 31, 2005]
[edit reason] examplified [/edit]

jdMorgan

6:12 pm on Aug 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I hope this is just a matter of confusion.

  • "http://www.example.com/page.html" is an unambiguous canonical URL.

  • "/page.html" is a server-relative URL. It should resolve identically to http://www.example.com/page.html

  • "page.html" is current-directory relative. It is resolved to a page in the same directory as the page on which this link appears, according to where the browser thinks it is in the URL-space, not according to the pages' location in server filespace.

  • "../page.html" is also current-directory relative. The browser resolves this by removing the current directory and page info from the current page's location, and appending "/page.html." In practice, this means, "Go up one URL-path-element and add this new path element."

    For server-wide navigation, you should be using either the canonical form, or the server-relative form.

    Jim

  • jd01

    6:15 pm on Aug 31, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Not as they should...

    ../about

    I am not sure why they would - they are in the file as a server relative path (/about/file.html) that is exactly how they will be displayed - Includes of html just consolidate code so you can change many places from a single file, they do not change what is in that file based on file location.

    They work when you put the full canonical path, because you have the full external path to the file, so the server knows where to look for it.

    Justin

    nigassma

    6:17 pm on Aug 31, 2005 (gmt 0)

    10+ Year Member



    That's what I figured... but the server-related form doesn't do as it should. Why?... I have no clue. That's the part that's getting me all confused.

    Should it be noted that 'nav.htm' IS in the root folder of the site. http://www.example.com/nav.htm...

    [edited by: jatar_k at 6:49 pm (utc) on Aug. 31, 2005]
    [edit reason] examplified [/edit]

    nigassma

    6:23 pm on Aug 31, 2005 (gmt 0)

    10+ Year Member



    And look at that... after stubbing my toe on my filing cabinet I turn around and the sever-relative way works... woo hoo! Sometimes my computer needs to have a laugh at me before it decides to wake up and do as I ask.

    Thanks for the help guys.

    jd01

    6:25 pm on Aug 31, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Just for future reference that is a browser cache problem - make sure you empty it before you reload the page to see the effects of changes.

    Justin

    jdMorgan

    6:27 pm on Aug 31, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Browser cache effect again...

    Jim

    nigassma

    6:32 pm on Aug 31, 2005 (gmt 0)

    10+ Year Member



    The nav markup that I posted earlier was an abbreviated version. Half of the links had a "/" preceding them and half didn't. Could that have been a part of the problem?

    jd01

    6:35 pm on Aug 31, 2005 (gmt 0)

    WebmasterWorld Senior Member 10+ Year Member



    Yes, consistency in structure will be critical for a file used in multiple directories throughout a site - everything should be server relative (have the /).

    Justin

    nigassma

    6:47 pm on Aug 31, 2005 (gmt 0)

    10+ Year Member



    Thanks.

    -Nick