Install Joomla in a subdirectory

六眼飞鱼酱① 提交于 2019-11-30 23:41:32
jonasfh

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.

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!