How to make relative links on the pages?

Tags: ,

By default, Joomla! inserts into a page absolute (”http://site.com/page”), instead of relative (”/page”) links. It has an advantage—for example if someone will copy the text of your pages all links still will point to your site. But authors of some sites wish, that on their site all links were relative since it can noticeably reduce the size of page.

For this purpose, as well as in the previous note (Why Homepage is “index.php?option=com_frontpage&Itemid=1″?), it is necessary to edit function “sefRelToAbs” in a file “/includes/sef.php” since the outputting of practically all links in Joomla! is fulfilled through this function.

We change (approximately 520-th line)

return $mosConfig_live_site . '/' . $string . $fragment;

to

return '/' . $string . $fragment;

and (approximately 555-th line)

$string = $mosConfig_live_site . '/' . $string;

to

$string = '/' . $string;

Related Posts

8 Responses to “How to make relative links on the pages?”

  1. 1
    Physicist Says:

    May be it’ll be interesting to anyone:
    Comment on problem with rss export after applying this patch.

  2. 2
    Chris Says:

    Hiya

    Annoyingly I am having to retype this because your form did not like my @{at} approach.

    Regardless, we seem to have the opposite problem. Our ’spider’ reports back lots of 404 errors from relative links. Is there a way to make relative links absolute?

    for example

    404: org_uri is http://www.rerere.uk/friends-alumni/gazette-and-newsletter/images/alumni/summernews2006.pdf

    because the code should in fact point to

    http://www.rerere.uk/images/alumni/summernews2006.pdf

    Any help advice would be appreciated…

    Cheers

    Chris

  3. 3
    Physicist Says:

    Most likely your link looks like “images/alumni/summernews2006.pdf” instead of “/images/alumni/summernews2006.pdf”.

  4. 4
    Chris Says:

    okay - i cannot change the href to either /xxx or the full link - any suggsetions?

  5. 5
    Physicist Says:

    Then try to add

    <base href="http://www.rerere.uk/" />

    into the head-section of your template (index.php). It is strange that this line is lacking in your page.

    (see page source of http://wadham.ox.ac.uk/friends-alumni/gazette-and-newsletter/wadham-gazette-newsletter.html :) )

  6. 6
    PG Says:

    /” /> is more proper for Joomla index.

  7. 7
    PG Says:

    …well. that didn’t work well. Sorry I do not know the proper syntax to style for code on this blog. What I meant to add was that for base href= in a Joomla template, it would be more proper to use $mosConfig_live_site

  8. 8
    Physicist Says:

    PG:
    You are right. In the general case it is more proper to write

    <base href="<?php echo $mosConfig_live_site; ?>/" />

You can follow any responses to this entry through the RSS 2.0 feed.

Leave a Reply