PHP Joomla! 6 Joomla! 5 Joomla! 3 (Legacy) Helper / API Basic

Get Root URL, Current URL and Build Query Strings with Uri

Uses Joomla\CMS\Uri\Uri to read the site root, current URL and safely append query parameters.

Updated on 24 November 2026 48 copies 169 views
components/com_example/src/Helper/UrlHelper.php
<?php

declare(strict_types=1);

use Joomla\CMS\Uri\Uri;

$rootFull    = Uri::root();              // https://pontomega.com.br/
$rootRel     = Uri::root(true);          // "" ou "/subpasta"
$currentFull = Uri::getInstance()->toString();

$shareUrl = clone Uri::getInstance();
$shareUrl->setVar('utm_source', 'newsletter');
$finalUrl = $shareUrl->toString();
Clone Uri::getInstance() before calling setVar() so you never mutate the shared global URI.
components/com_example/src/Helper/UrlHelper.php
<?php
$rootFull    = JURI::root();
$rootRel     = JURI::base(true);
$currentFull = JURI::current();
Legacy Joomla 3 version via JURI::root() and JURI::current().

Technical explanation and best practices

Joomla\CMS\Uri\Uri replaces legacy JURI and properly handles subdirectory installations, HTTPS reverse proxies and URL-encoded query strings.

Direct Engineering

Have a Joomla project or technical challenge in mind?

From architectural diagnosis to production deployment, directly with the engineer.