0

Having a strange issue with J3.3.6. The <base> tag href is always pointing to the root / homepage of my name, e.g www.example.com, even when on an inner page. I only noticed when trying to use an anchor, and the anchor used the base href and linked to the homepage.

I haven't come across this issue with any other sites I've built on 3.3.6, and as far as I can tell there aren't any other differences. I've tried:

  • Resetting .htaccess to the J! default (I added in a few cache control headers - no change)
  • Switching off SEF URLs (see below)
  • Checking $live_site in configuration.php (no value set)

When I switch off SEF URLs and URL re-writing, the base href is disappears (only the canonical link remains, which is correct).

If I edit /libraries/joomla/html/document/renderer/head.php, around line 74 - 76 to use JURI::current() instead of $document->getBase(); then the correct URLs at used in the base value if SEF URLs are enabled - but I've never had to do this before and obviously this will be wiped on upgrade. If SEF URLs are off this is wrong as it just goes to index.php without any query parameters, causing the same sort of issue in reverse (anchors all go to the homepage).

1 Answer 1

1

That is the whole point of the <base> tag. It's supposed to point to the root of your website which makes using relative link easier, and with Joomla, this gets automatically added to the <head> by the following code snippet:

<jdoc:include type="head" />

I'm not sure how your anchors are setup but if you use the following for example:

<a href="#section">anchor</a>

<div id="section">
    <p>content here</p>
</div>

Then upon clicking the anchor, it will take you to the #section ID

If this doesn't work, then it might be something that your template is doing. Try changing the template to the default Protostar one and see if you have the same issue.

7
  • Fundamental misunderstand of the base tag on my part there. Thanks for this - going to have a quick look at some docs... Commented Jan 22, 2015 at 12:22
  • Weird, then, on the throwaway site I set up it's now setting the base as the full URL. Hm. Commented Jan 22, 2015 at 12:26
  • Wooops or not. I'm off for coffee and a cry. Commented Jan 22, 2015 at 12:43
  • 1
    In HTML, the <a> tag has no name attribute. You should be using href as shown ;)
    – Lodder
    Commented Jan 22, 2015 at 12:46
  • It's all gone horribly, horribly wrong this morning :( Commented Jan 22, 2015 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.