3
votes

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

4 Answers

6
votes

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.

1
votes

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.

0
votes

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

0
votes

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.