?
avatar infograf768
infograf768
25 Aug 2016

The <base tag in Joomla is displaying the page link in the html header.
Code is:

        if (!empty($base))
        {
            $buffer .= $tab . '<base href="' . $base . '" />' . $lnEnd;
        }

Example when joomla is in the trunkgitnew folder and the page anicearticle.html is displayed:
<base href="http://localhost:8888/testwindows/trunkgitnew/anicearticle.html" />

But at reading the specs for that tag
http://www.w3schools.com/tags/tag_base.asp
http://www.w3schools.com/TAGs/att_base_href.asp

we can see
The <base> tag specifies the base URL/target for all relative URLs in a document.

Therefore shall we not use rather:

        if (!empty($base))  // now useless...
        {
            $buffer .= $tab . '<base href="' . JUri::base() . '" />' . $lnEnd;
        }

to get:
<base href="http://localhost:8888/testwindows/trunkgitnew/" />

avatar infograf768 infograf768 - open - 25 Aug 2016
avatar infograf768 infograf768 - change - 25 Aug 2016
The description was changed
avatar infograf768 infograf768 - edited - 25 Aug 2016
avatar brianteeman
brianteeman - comment - 25 Aug 2016

NEVER EVER use w3schools as a reference for anything

https://developer.mozilla.org/en/docs/Web/HTML/Element/base

Examples
< base href="http://www.example.com/page.html">
< base target="_blank" href="http://www.example.com/page.html">

avatar brianteeman
brianteeman - comment - 25 Aug 2016

So to answer your question - NO


This comment was created with the J!Tracker Application at issues.joomla.org/joomla-cms/11784.

avatar andrepereiradasilva
andrepereiradasilva - comment - 25 Aug 2016

Does Joomla use the base tag as should?

Reading the mozzila specifications i think it's ok.

Also check the W3C specifications: https://www.w3.org/TR/html5/document-metadata.html#the-base-element
And the W3C wiki: https://www.w3.org/wiki/HTML/Elements/base

avatar ggppdk
ggppdk - comment - 25 Aug 2016

I do not know why it was added like this in the first place,
now it can not be changed without B/C break ?

you need

<base href="http://localhost:8888/testwindows/trunkgitnew/anicearticle.html" />

so that anchor links will work ,and using JS to convert them is not an 100% solution,
for anchor links to work (without any JS code),

  • either you do not add it
  • or you add like the above

then because all relative links will break by the above BASE TAG,

  • you have the SEF plugin searching and converting all relative urls so that they include the joomla subfolder path

(but that is not the only reason that SEF plugin needs to do this)
someone could provide more details about the choices behind using the base tag like this

avatar mbabker
mbabker - comment - 25 Aug 2016

someone could provide more details about the choices behind using the base tag like this

I'm going to be honest here. Looking for responses to things like this is kind of pointless unless you're looking for design decisions on features implemented in the last couple of years. How many of the developers who made design decisions on the features or API of 1.5 or 1.6 are still with the project?

The best you can do at this point is just play the hand you've been dealt.

avatar ggppdk
ggppdk - comment - 25 Aug 2016

I'm going to be honest here. Looking for responses to things like this is kind of pointless unless you're looking for design decisions on features implemented in the last couple of years. How many of the developers who made design decisions on the features or API of 1.5 or 1.6 are still with the project?

i am just saying that i do not know, and if someone had the answer , it would be interesting / beneficial to know

anyway the original question has been answered, right ?

<base href="http://localhost:8888/testwindows/trunkgitnew/anicearticle.html" />

is indeed (currently) intensional

avatar mbabker
mbabker - comment - 25 Aug 2016

Johan seems to be getting involved with the project again, if he had something to do with JDocument he might remember why it's the way it is. Otherwise, instead of trying to answer a "why is it this way now" question, you're probably better off looking for a "is this adequate for our use cases today and if not how can we change it?" answer.

avatar brianteeman brianteeman - change - 26 Aug 2016
Labels Added: ?
avatar johanjanssens
johanjanssens - comment - 29 Aug 2016

@infograf768 Short answer no, if you do what you propose relative links will start breaking. You can easily test is with anchor links.

For the more technical explanation. The base tag implementation is based on the html spec. Which says the following:

  1. "When present, the BASE element must appear in the HEAD section of an HTML document, before any element that refers to an external source. The **path information specified by the BASE element** only affects URIs in the document where the element appears."

See: https://www.w3.org/TR/html4/struct/links.html#h-12.4

The base path is used calculate relative URL's. For content management systems that decouple presentation from content the base element allows for content portability.

The spec defines rules on how the base tag is used to lookup the actual url when a relative url is given. It also specifies what happens if no base URI is defined.

  1. By default, **the base URI is that of the current document**. Not all HTML documents have a base URI (e.g., a valid HTML document may appear in an email and may not be designated by a URI). Such HTML documents are considered erroneous if they contain relative URIs and rely on a default base URI.

See: https://www.w3.org/TR/html4/struct/links.html#h-12.4.1

Based on info from 1 and 2, the spec says that the base URI need to contain the path and by default the path should be that of the current document.

Per example the current document path is /testwindows/trunkgitnew/anicearticle.html not /testwindows/trunkgitnew/. The later is not a full path and cannot be used by the browser to correctly resolve relative URL's.

What is the relation to JURI::base()?

JURI:base() as the function says will return the base URL of the application (using information from the REQUEST or based on the live_site config option) By default Joomla considers the base URI to be root URI, for the administrator application '/administrator' is added.

Example: domain http://www.test.com/folder/to/site

For site application

For administrator application

What is the relation to JPATH_BASE?

In the Joomla API's anything that includes 'base' is considered to be dependant on the application context. For example JPATH_BASE will result to the base path the application being run, for the administrator this will return the root path + '/administrator'.

Why are we adding the base html tag if it could also be omitted?

Back in the days relative path resolution wasn't as well implemented in browsers as it is today, it was advised to define your own base path. We also wanted the base path to be configurable, in case base path and base site url would not be the same.

Historical references

The (original) Joomla Framework is designed to allow to be decoupled from the application that was using it. This was not the case with Mambo or Joomla 1.0, it's url's and paths were hardcoded.

The decoupled approach we introduced allowed the framework to be used to create separate applications easily. For example, you could use it to create a bridge between Joomla and other PHP systems - which at that time was a highly requested and discussed topic - re-using the Joomla application context such as session and routing to integrate both apps.

The approach also make it very easy to bootstrap Joomla in just a few lines of code. I gave a talk on this topic at the Joomladay 2008 in The Netherlands. See: http://www.slideshare.net/joomlatools/joomladag-nl-2008-joomla-15-application-layer

Hope that helps.

avatar johanjanssens
johanjanssens - comment - 29 Aug 2016

@ggppdk The SEF plugin and how it works is unrelated to this issue. The SEF plugin includes code to warrant 100% BC between Joomla 1.0 and 1.5.

It was intended to be phased out in a later stage. We planned for rewriting URL's to become the default for Joomla 2. We didn't do this in 1.5 as not all extensions supported the router yet and we didn't wanted sites to break.

Today we still allow users to configure this, which adds unneeded code complexity for users and developers. Extension developers still need to test their extensions with SEF on and off.

avatar infograf768
infograf768 - comment - 30 Aug 2016

Hope that helps.

It does. Thanks.

avatar infograf768
infograf768 - comment - 30 Aug 2016

Closing the issue.

avatar infograf768 infograf768 - change - 30 Aug 2016
Status New Closed
Closed_Date 0000-00-00 00:00:00 2016-08-30 06:09:46
Closed_By infograf768
avatar infograf768 infograf768 - close - 30 Aug 2016

Add a Comment

Login with GitHub to post a comment