Skip to main content
Inspiring
February 20, 2009
Question

Menu links in Include file

  • February 20, 2009
  • 2 replies
  • 287 views
Hi folks,

I am knocking up a new site and after many template-fueled complications in the past I have decided to try using includes for the header, footer, and menus. Brilliant! it all works. But the only drawback I have is that the links will not work for pages that are in different directories.
The only solution I can think of is that I use an absolute address for every link - which seems a bit of a nightmare, particularly as I would have to name them for my testing environment then change them when I went live every time.

Are absolute links the only solution or am I missing a trick here?

Cheers


Dave
This topic has been closed for replies.

2 replies

Inspiring
February 20, 2009
.oO(davecheet)

> I am knocking up a new site and after many template-fueled complications in
>the past I have decided to try using includes for the header, footer, and
>menus. Brilliant! it all works. But the only drawback I have is that the links
>will not work for pages that are in different directories.

Use root-relative URLs, starting with a slash, e.g.

<a href="/">Home</a>
<a href="/about">About us</a>
<a href="/contact">Contact</a>
... whatever

These will work on all pages, regardless of their directory level.

> The only solution I can think of is that I use an absolute address for every
>link - which seems a bit of a nightmare, particularly as I would have to name
>them for my testing environment then change them when I went live every time.

You only need a local testing server (which you should have anyway),
nothing more. Then on your local machine the above "About us" URL will
resolve to < http://localhost/about>, but to < http://example.com/about>
on the live site. You don't have to change anything.

Micha
Inspiring
February 20, 2009
"davecheet" <webforumsuser@macromedia.com> wrote in message
news:gnmbik$7et$1@forums.macromedia.com...
> I am knocking up a new site and after many template-fueled
> complications in
> the past I have decided to try using includes for the header,
> footer, and
> menus. Brilliant! it all works. But the only drawback I have is that
> the links
> will not work for pages that are in different directories.


Inside the menu, use links relative to the site root. To test the site
locally, create a virtual host in Apache or a new web site in IIS7. If
you're using IIS6, you need to locate the site in the top level of
C:\inetpub\wwwroot.

--
David Powers
http://foundationphp.com