在子目录中安装 Joomla

Install Joomla in a subdirectory

你们中的一些人可能知道,Wordpress 在设置中有一个选项允许将站点安装在子目录中,同时让站点 URL 成为主域。它类似于 "Site url" 和 "Wordpress url"。我在 Joomla 中寻找类似的东西。我知道它没有内置选项,但如果可能的话,我宁愿不必移动所有文件。请向我解释一下,就像对一个五岁的孩子一样,以防万一:)

我以前为此使用过一个名为 Virtual Domains 的扩展程序。根据他们的说法,它提供

Multi-domain capability for Joomla without changing the Joomla core files.

。我以前用过,效果很好

您可以在您的 joomla 安装中覆盖 /includes/defines.php 文件。将此文件复制到安装的根文件夹,然后将所有文件夹名称更改为您喜欢的设置。

在 /index.php 中,您会看到它如何首先检查 /defines.php 是否存在。如果未定义 _JDEFINES,它会继续加载 /includes/defines.php。所以一定要包括

define('_JDEFINES', 'TRUE');

在您覆盖的 /defines 中。php-file。祝你好运:)

下面是 index.php 加载文件夹定义的方式:

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';
}

我现在看到您可以用类似的方式覆盖 /administrator 中的文件夹位置,将 /administrator/includes/defines.php 复制到 /administrator 并覆盖此处的文件夹。

要将整个 joomla 安装移动到服务器上的子文件夹 (http://example.com/subdir), but still access it from the root (http://example.com),我执行了以下操作:

  • 将整个安装移动到 subdir-folder
  • 在configuration.php中,设置$live_site = "http://example.com";
  • 同时更改 configuration.php
  • 中的 tmp 和 log-folders
  • 在 root-folder 中添加一个 .htaccess-file:

(代码修改自this excellent answer)

RewriteEngine on
RewriteCond %{THE_REQUEST} subdir/
RewriteRule ^subdir/(.*) http://example.com/ [R=301,L]
RewriteCond %{REQUEST_URI} !subdir/
RewriteRule ^(.*)$ /subdir/ [L]

修改默认的 joomla .htaccess-file,现在在 /subdir-folder 中,以包含一个 RewriteBase:

RewriteBase /subdir/

经过这些修改后,似乎一切都按应有的方式运行。

我首先尝试了接受的答案。但是,该答案还会将现有文件和文件夹重定向到新的子目录。

出于这个原因,我使用了:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdir/
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ subdir/index.php [L]

相反。

我知道这不是最好的解决方案,因为它没有正确隐藏子目录。但是,它允许保持该站点上的现有代码正常工作。