以下是我对public_html 目录 的域指向和结构的理解:
单个 Drupal 站点(默认)
/public_html <-- where example.com, www.example.com, dev.example.com are pointing
.htaccess <-- root's .htaccess
index.html <-- http://example.com, http://www.example.com
/dev <-- drupal root folder
.htaccess <-- drupal's .htaccess
index.php <-- http://dev.example.com
/sites <-- drupal's file system folder
/default <-- drupal's default subfolder
setting.php <-- drupal's default setting (dev.example.com)
如果以上内容正确,那么我想推荐如下:
根的 .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^dev
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule ^(.*)$ dev/$1 [L]
设置.php:
# $base_url = 'http://www.example.com'; // NO trailing slash!
要在你的 url 上没有一个干净的/dev/
url,找到包含上述代码的行,删除前导井号并填写 Drupal 安装的绝对 URL,如下所示:
$base_url = 'http://dev.example.com'; // NO trailing slash!
在浏览器上打开您的网站。一旦您以管理员身份登录到您的 drupal 站点,请在以下管理菜单下检查或设置公共文件系统路径的正确路径:
Home » Administration » Configuration » Media » File System
验证或更正该值以:
sites/dev.example.com/files, for your site dev.example.com via access url:
http://dev.example.com/#overlay=%3Fq%3Dadmin%252Fconfig%252Fmedia%252Ffile-system
多 Drupal 站点(按子域)
您可以考虑为您的 drupal 站点进行多站点配置http://dev.example.com
,因此您可以为其他子域设置默认文件夹,http://prod.example.com
如下所示:
/public_html <-- example.com, www.example.com, dev.example.com, prod.example.com
.htaccess <-- root's .htaccess
index.html <-- http://example.com, http://www.example.com
/dev <-- drupal root folder
.htaccess <-- drupal's .htaccess
index.php <-- http://dev.example.com, http://prod.example.com
/sites <-- drupal's file system folder
/default <-- drupal's default subfolder
setting.php <-- drupal's default setting (prod.example.com)
/dev.example.com <-- drupal's dev.example.com subfolder
setting.php <-- drupal's dev.example.com setting
根的 .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(dev|prod)
RewriteCond %{REQUEST_URI} !^/dev/
RewriteRule ^(.*)$ dev/$1 [L]
然后在每个 settings.php 上删除前导井号$base_url
并填写您的 Drupal 安装的绝对 URL。
验证或更正每个子域 的公共文件系统路径的值,如下所示:
sites/dev.example.com/files, for your site dev.example.com via access url:
http://dev.example.com/#overlay=%3Fq%3Dadmin%252Fconfig%252Fmedia%252Ffile-system
sites/prod.example.com/files, for your site prod.example.com via access url:
http://prod.example.com/#overlay=%3Fq%3Dadmin%252Fconfig%252Fmedia%252Ffile-system
多 Drupal 站点(按子域 + URL 的路径)
您还可以扩展上述多站点配置,您可以在您的 url 路径http://dev.example.com
下设置另一个 drupal 站点(与 共享相同的 drupal 根文件夹),例如:
http://dev.example.com/site1,
http://dev.example.com/site2, etc..
其中site1和site2是通过以下 shell 命令指向 drupal 根文件夹的符号链接:
$ cd /path/to/your/public_html/dev
$ ln -s . site1
$ ln -s . site2
所以目录结构如下:
/public_html <-- example.com, www.example.com, dev.example.com, prod.example.com
.htaccess <-- root's .htaccess
index.html <-- http://example.com, http://www.example.com
/dev <-- drupal root folder
.htaccess <-- drupal's .htaccess
index.php <-- http://dev.example.com, http://prod.example.com
/site1 <-- http://dev.example.com/site1
/site2 <-- http://dev.example.com/site2
/sites <-- drupal's file system folder
/default <-- drupal's default subfolder
setting.php <-- drupal's default setting (prod.example.com)
/dev.example.com <-- drupal's dev.example.com subfolder
setting.php <-- drupal's dev.example.com setting
/dev.example.com.dev.site1 <-- drupal's dev.example.com.site1 subfolder
setting.php <-- drupal's dev.example.com.site1 setting
/dev.example.com.dev.site2 <-- drupal's dev.example.com.site2 subfolder
setting.php <-- drupal's dev.example.com.site2 setting
root 的 .htaccess的代码同上,同样步骤在setting.php中填写 $base_url 的绝对 URL ,并验证或更正新站点 的Public file system path的值:
sites/dev.example.com.dev.site1/files, for your site dev.example.com.site1 via access url:
http://dev.example.com/site1/#overlay=%3Fq%3Dadmin%252Fconfig%252Fmedia%252Ffile-system
sites/dev.example.com.dev.site2/files, for your site dev.example.com.site2 via access url:
http://dev.example.com/site2/#overlay=%3Fq%3Dadmin%252Fconfig%252Fmedia%252Ffile-system
多 Drupal 站点(通过 Drupal-8)
通过 Drupal-8,不再需要符号链接,可以更灵活地为站点设置命名/public_html/dev/sites下的文件夹并将它们放在sites.php文件中,如下所示:
$sites = array(
'dev.example.com' => 'dev',
'dev.example.com.site1' => 'dev.site1',
'dev.example.com.site2' => 'dev.site2',
);
所以目录结构如下:
/public_html <-- example.com, www.example.com, dev.example.com, prod.example.com
.htaccess <-- root's .htaccess
index.html <-- http://example.com, http://www.example.com
/dev <-- drupal root folder
.htaccess <-- drupal's .htaccess
index.php <-- http://dev.example.com, http://prod.example.com
/sites <-- drupal's file system folder
sites.php <-- drupal's multisite setting
/default <-- drupal's default subfolder
setting.php <-- drupal's default setting (prod.example.com)
/dev <-- drupal's dev.example.com subfolder
setting.php <-- drupal's dev.example.com setting
/dev.site1 <-- drupal's dev.example.com.site1 subfolder
setting.php <-- drupal's dev.example.com.site1 setting
/dev.site2 <-- drupal's dev.example.com.site2 subfolder
setting.php <-- drupal's dev.example.com.site2 setting
最后,为确保一切设置正确,建议您在设置新站点时通过访问以下菜单清除缓存:
Home » Administration » Configuration » Development » Clear all Caches
为了您的方便,我已经为Drupal Multisite设置了一个简单的演示站点,如上所述。我还在这里维护这个特定主题的文档。