How to Get URI in Joomla

The JUri Class can be used to get information about the Joomla URI.

This class serves two purposes.

  1. It parses a URI and provides a common interface for the Joomla Platform to access and manipulate a URI.

  2. It obtains the URI of the current executing script from the server regardless of server.

$uri = JUri::getInstance();

It returns the global JUri object, only creating it if it doesn't already exist.

Difference Between URL and URI

The URL stands for Uniform Resource Locator. The URI stands for Uniform Resource Identifier. A URI can be a name, locator, or both for an online resource whereas a URL is just the locator. URLs are a subset of URIs.

Components of URL or URI

A URL is normally made up of four components:

  1. Scheme: The scheme identifies the protocol used to access the resource on the Internet. It can be HTTP (without SSL) or HTTPS (with SSL).

  2. Host: The host name identifies the host that holds the resource. For example, Host names can also be followed by a port number. Well-known port numbers are normally omitted from the URL.

  3. Path: The path identifies the specific resource in the host that the web client wants to access. For example, /documentation/joomla/index.html.

  4. Query String: The query string follows the path. It provides information that the resource can use for several purpose. For example, as parameters for a search or as data to be processed. The query string is usually a string of name and value pairs. For example, view=article. Name and value pairs are separated from each other by an ampersand (&). For example, view=article&search=joomla.


The scheme is followed by a colon and two forward slashes. If a port number is specified, that number follows the host name, separated by a colon. The path name begins with a single forward slash. If a query string is specified, it is preceded by a question mark.

A URL can be followed by a fragment identifier. The separator used between the URL and the fragment identifier is the # character. A fragment identifier is used to point a web browser to a reference or function in the item that it has just retrieved. For example, if the URL identifies an HTML page, a fragment identifier can be used to indicate a subsection within the page, using the ID of the subsection.

Joomla JUri Class

1. To get the global JUri object, only it if it doesn't already exists.

$uri = JUri::getInstance();

2. To get the complete or full URI

echo $uri;


echo $uri->__toString();

3. To get the scheme (http or https)

echo $uri->getScheme();

To check if the scheme uses SSL

echo $uri->isSsl();

4. To get the host

echo $uri->getHost();

It returns the hostname or ip or null if no hostname or ip was specified.

5. To get the base URL or root URL

echo $uri->base();
echo $uri->root();

6. To get the path of URL after the root.

echo $uri->getPath();

It includes a forward slash at the starting and excludes any query string parameters.

7. To get the URL without any query string parameters

echo $uri->current();

8. To get the query string parameters

echo $uri->getQuery();

Add the boolean true argument to get query string parameters as array.

$arr = $uri->getQuery(true);

To get a specific query string variable by name 

echo $uri->getVar('type');

You can also declare a default value as the second argument if the variable is not set.

To check if a variable exists

echo $uri->hasVar('type');

9. To Remove an item from the query string variables if it exists


10. To get URI port number


It returns null if no port was specified. 

Star InactiveStar InactiveStar InactiveStar InactiveStar Inactive