So far, I am finding it difficult to run Joomla 4 in a subdirectory. With $live_site empty or set to https://example.com or https://example.com/ the site shows an error message "The requested page can't be found" when an attempt is made to access https://example.com/testing or https://example.com/testing/index.php.

With $live_site set to https://example.com/testing, I can access the home page. But all component links are wrong because Uri::root() returns "https://example.com/testing/" and \Joomla\CMS\Router\Route::_ returns "testing/index.php?...." (with SEF turned off) thus duplicating the subdirectory and creating an invalid link when combined.

Am I missing something?

  • You wan to run J! from subdirectory but without having it in the URL?
    – Sharky
    Sep 22 at 17:24

2 Answers 2


Have you considered installing it in a sub-domain instead? e.g. https://testing.example.com

  • Yes, that certainly works, thanks. The trouble is that I am the developer of an extension and some users want to run their sites in a subdirectory. So I am trying to figure out whether this is possible in Joomla 4, and if so, how the extension can build valid links.
    – mbrampton
    Sep 23 at 9:17

This explanation assumes your Joomla instance is in /public_html/testing and the URL will be www.example.com without the '/testing' string appearing in the URL.

To run Joomla in a sub directory you need need to update the $live_site so that it contains just the domain name, no mention of the sub-directory, eg.


In the /public_html/.htaccess you then 'hide' the sub-directory name with a little bit of code

# Internally Rewrite requests for Example to hide the sub-directory in the URL
# when using the primary cpanel domain rather than an Add-on domain.
# If the target directory holds a Joomla instance then the configuration.php
# entry for $live_site needs to contain the full domain name also, eg.
# $live_site='https://www.examle.com' for this hack to work.
# The $ 1!^directory allows you to access other directories and not be affected by this,
# eg. www.example.com/anotherdirectory

    RewriteCond %{HTTP_HOST} ^www\.example\.com$
    RewriteCond $1 !^anothedirectory
    RewriteRule (.*)$ /testing/$1 [L]

Some things to note is that above normally only needs to used when the hosting account, eg. cPanel, forces the primary domain to use the /public_html/ root folder. For all other domains then use sub-domains or Add-on domains.

From the point of view of the extension being developed you should not need to be concerned about any of the above if you use the normal methods to let Joomla resolve the domain and/or prefix the directory names in your code.

This approach has worked since Joomla 1 and still works with Joomla 4.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.