【问题标题】:Redirecting another domain to an existing drupal installation's subdirectory将另一个域重定向到现有的 drupal 安装的子目录
【发布时间】:2014-01-16 22:59:05
【问题描述】:

在过去的几个小时里,我一直在尝试解决一个问题。我急需帮助!

我有两个域:

rd1.example.com/drupal
rd2.example.com

我在 rd1.example.com/drupal/ 中有一个 drupal 安装

此外,我开始使用 url 别名在 drupal 上创建内容:rd1.example.com/drupal/rd2/

我想要做的是使用第二个网站来指向我的 drupal 安装中的特定内容:

rd2.example.com -> rd1.example.com/drupal/rd2/

我不希望它是一个重定向,而是一个内部隐藏的重定向。用户会认为他们在 rd2.example.com 上。

我已将 rd2.example.com 切换为指向安装 drupal 的目录。我一直在尝试编辑 drupal 的 .htaccess 上的重写规则,但没有运气。任何帮助是极大的赞赏。到目前为止,这是我的规则:

#Existing settings
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} !^rd2\.example\.com [NC]
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^ index.php [L]

#New rules to accomodate for rd2.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^rd2\.example\.com$ [NC]
RewriteCond %{DOCUMENT_ROOT}/rd2%{REQUEST_URI} -f
RewriteRule .* /rd2/$0 [L]

【问题讨论】:

  • /drupal/rd2/ 目录真的存在吗?还是应该由 drupal 提供的虚拟路径?
  • drupal 提供的虚拟路径。在内部,drupal 知道这应该指向哪个页面。它在物理上并不存在

标签: .htaccess mod-rewrite drupal drupal-7


【解决方案1】:

Drupal 依赖服务器变量来处理其请求。这意味着当您在内部重写为/rd2/$0 时,drupal 不知道如何处理它。您需要从 rd2` 子域反向代理 *。所以让 drupal 保持原样,然后在 rd2.example.com 文档根目录中添加:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^rd2 [NC]
RewriteRule ^(.*)$ http://rd1.example.com/drupal/rd2/$1 [L,P]

这只有在你的服务器上加载了 mod_proxy 时才有效,否则什么都不会发生。 Mod_proxy 只能通过您服务器的配置打开。您还可以从 rd2 子域的 vhost 配置中设置反向代理:

ProxyPass / http://rd1.example.com/drupal/rd2/

【讨论】:

  • Yeap 的工作就像我的魅力一样。我使用了 proxypass,因为它似乎比在 apache 的配置中激活配置更安全。
【解决方案2】:

除了代理之外,您还可以考虑使用由 shell 命令生成的符号链接,如下所示:

ln -s /path/to/rd1 /path/to/drupal/rd2

更多细节在Multi-site - Sharing the same code base中解释

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-11
    • 1970-01-01
    • 1970-01-01
    • 2014-06-26
    • 2019-08-22
    • 2014-07-03
    • 2013-05-27
    相关资源
    最近更新 更多