As some of you may know, Wordpress has an options in settings to allow site installation in a subdirectory, while having the site URL be the main domain. It was something like "Site url" and "Wordpress url". I'm looking for something like this in Joomla. I know there is no inbuilt option for it, but I'd rather not have to move all the files if possible. And please, explain it to me like to a five year old, just in case :)
4 Answers
To move the whole joomla installation to a subfolder on the server (http://example.com/subdir), but still access it from the root (http://example.com) I did the following:
- Move your whole installation to the subdir-folder
- In configuration.php, set $live_site = "http://example.com";
- Also change the tmp and log-folders in configuration.php
- Add a .htaccess-file to the root-folder:
(The code is modified from this excellent answer)
RewriteEngine on
RewriteCond %{THE_REQUEST} subdir/
RewriteRule ^subdir/(.*) http://example.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !subdir/
RewriteRule ^(.*)$ /subdir/$1 [L]
Modify the default joomla .htaccess-file, now in the /subdir-folder, to include a RewriteBase:
RewriteBase /subdir/
After these modifications it seems everything works the way it should.
-
Tip: I had to add these codes: https://stackoverflow.com/a/7781331/5681573 in order to let your rewriterules also work for the administrator page of Joomla with no trailing slash at the end. – Cinzel Jul 30 '17 at 12:33
You can override the file /includes/defines.php in your joomla installation. Copy this file to the root folder of your installation, and then change all folder names to how you like your setup.
In /index.php you see how it first checks if /defines.php exists. Then it goes on to load /includes/defines.php if _JDEFINES is not defined. So be sure to include
define('_JDEFINES', 'TRUE');
in your overridden /defines.php-file. Good luck :)
Below is how index.php loads folder definitions:
if (file_exists(__DIR__ . '/defines.php')){
include_once __DIR__ . '/defines.php';
}
if (!defined('_JDEFINES')){
define('JPATH_BASE', __DIR__);
require_once JPATH_BASE . '/includes/defines.php';
}
I see now that you are able to override folder locations in /administrator in a similar matter, copy /administrator/includes/defines.php to /administrator and override folders here.

- 4,151
- 2
- 21
- 37
-
Sorry for late response. But I think I'm lost. site.com/folder/index.php is the root of my installation. I want to access site.com and have the site appear without having to move all files from /folder to root. Could you dumb it down for me, what I have to do? – Kard Nails Jan 26 '16 at 14:12
-
I think the easyest way to achieve this is using .htaccess, as explained here: http://stackoverflow.com/questions/10364951/make-web-root-folder-a-sub-folder-with-htaccess . If you are already using the .htaccess-file for your site it might be a bit tricky, as you'll need to modify it to fit the pattern explained... – jonasfh Jan 26 '16 at 14:26
I have used an extension called Virtual Domains for this before. According to them it provides
Multi-domain capability for Joomla without changing the Joomla core files.
. Which I have made use of previously and it works well

- 956
- 7
- 21
-
Thanks. I will look into it, but at first glance it seems like using a sledgehammer to crack a nut. – Kard Nails Jan 20 '16 at 10:39
-
I agree with you. But the only other way I see this being possible is to create a similar add on to achieve the results you need to your specifications. – Sphinx Jan 20 '16 at 12:30
I first tried the accepted answer. However, that answer also redirects existing files and folders to the new subdir.
For this reason I used:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdir/index.php [L]
instead.
I'm aware that this is not the best solution as it doesn't hide the sub directory properly. However, it allows to keep the existing code on that site working.

- 1,783
- 1
- 24
- 28