Actions

JURI/root

From Joomla! Documentation

A static method that returns the root URI of the Joomla site. If Joomla has been installed in the web server's document root then this method will return "/" for the path.

Syntax

string root( $pathonly, $path )

where:

Argument Data type Description Default
$pathonly boolean If true then only the path to the Joomla site is returned; otherwise the scheme, host and port are prepended to the path. Note that when true the URI returned has a trailing "/", but when false the trailing "/" is omitted. false
$path string Path to override the actual path. Since this is held statically it will affect all subsequent calls to this method.

Example

In this example, the Joomla root URI is shown with both values of the $pathonly argument. A new path is also applied and it should be noted that it affects subsequent calls to this method.

echo 'Joomla root URI is ' . JURI::root() . "\n";
echo 'Joomla root URI (path only) is ' . JURI::root( true ) . "\n";
echo 'Joomla root URI (path specified) is ' . JURI::root( false, '/a-different-path' ) . "\n";
echo 'Joomla root URI (path only) (path specified) is ' . JURI::root( true, '/a-different-path' ) . "\n";
echo "\n";
echo 'Joomla root URI is ' . JURI::root() . "\n";
echo 'Joomla root URI (path only) is ' . JURI::root( true ) . "\n";

might output

Joomla root URI is http://localhost/joomla15svn10812/
Joomla root URI (path only) is /joomla15svn10812
Joomla root URI (path specified) is http://localhost/a-different-path/
Joomla root URI (path only) (path specified) is /a-different-path

Joomla root URI is http://localhost/a-different-path/
Joomla root URI (path only) is /a-different-path

See also