Let's say I want to put a link in the footer that takes you to the copyrights page. How do I link the page correctly without giving the full absolute url?

<a href="copyrights">copyrights</a>
The above will not work if I'm on page other than home. Because if I'm on page http://site.com/about for example the link will resolve at http://site.com/about/copyrights, which will give a page not found.

<a href="../copyrights">copyrights</a>
The above will not work either because if I'm on a page like http://site.com/about/history for example the link will still resolve at http://site.com/about/copyrights, which again gives a page not found.

I would like to know the correct way to give a relative link that will resolve at http://site.com/copyrights from all pages within the site. Is this possible?

Comments

RobRoy’s picture

Check out the PathFilter module which converts any string like "internal:node/99" to the accurate path. It's in early beta and we're still working on some options, but it should be solid in the near future and will do what you want.

--
Rob
Founder and Director
Electronic Insight Corporation

Recent Drupal Projects: MP3PIG | MySpace Layouts

iraszl’s picture

Works beautifully on all pages, where input formats apply. But it does not work for settings page, for example "internal:page" will not work in the footer. Am I correct?

Coquevas’s picture

Try

<a href="/copyrights">copyrights</a>

The result will be:

www.example.com/copyrights

where "www.example.com" is your domain.

iraszl’s picture

This only works if the site is in the top level directory, such as http://example.com, but will not work if the site is installed in subdirectory like http://example.com/drupal, because all links will resolve at http://example.com/page rather than http://example.com/drupal/page. Good to have this option though.
--
Creativine: Brands coming alive as Drupal themes

Coquevas’s picture

Then try modify your template to include the base URL.

Base URL explanation

iraszl’s picture

Thanks!
--
Creativine: Brands coming alive as Drupal themes

iraszl’s picture

I added this to the theme: <?php global $base_url; ?><base href="<?php print $base_url; ?>/" />

It results in html: <base href="http://example.com/drupal/" />

This combined with the link formatted as "internal:page" gives me the correct http://example.com/drupal/page links anywhere on the site.

eberian’s picture

I think I also had the problem you describe. I had the Path Filter installed and turned on (took me a while to realise it was in the "Import Formats" a.k.a. "admin/filter" section). The "internal:" string was being removed, but only relative links ("files/file1.pdf" not "/dev/files/file1.pdf") were being generated.

What was happening was the Path Filter had a weight of 10, and the HTML Filter had a weight of 0. The HTML Filter was stripping out the "internal:" string before the content was passed to the Path Filter. Setting a weight of -1 for the Path Filter solved the problem, and removed the need for the base tag. It now works beautifully.

Surely, if the Path Filter module is working properly, you should not need to set an html base tag? If you use the base tag, then intra-page links like "#section2" may stop working.

Hope this helps,
Ed