Website Building » Joomla » How do I get the current URL in Joomla?

How do I get the current URL in Joomla?

Last updated on September 25, 2022 @ 8:15 am

There are a few ways to get the current URL in Joomla. The most common way is to use the url() function. For example, to get the URL for the current page, you would use url() as follows:

url(http://localhost/Joomla/administrator/components/com_content/views/article/view.html?id=1&category=1)

Another way to get the URL for the current page is to use the global $page variable. For example, to get the URL for the current page, you would use the following code:

PRO TIP: The following question is often asked in the Joomla community forums:

“How do I get the current URL in Joomla?”

The answer to this question is usually given as follows:

$this->baseurl

However, this answer is incorrect and can lead to undesirable results. The correct answer is actually:

$this->baseurl . ‘/’ . $this->request->getVar(‘option’)

echo $page;.

Dale Leydon

Dale Leydon

Sysadmin turned Javascript developer. Owner of 20+ apps graveyard, and a couple of successful ones.