【问题标题】:.htaccess rewrite to another domain on the same server without url change.htaccess 重写到同一服务器上的另一个域而不更改 url
【发布时间】:2012-02-10 03:46:23
【问题描述】:

我有一个具有“漂亮网址”的网络应用程序。那里的.htaccess 文件如下所示:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^([a-z0-9]+)(/)?([a-z0-9]+)?$ /home/user/domains/domain1.com/public_html/sites/index.php?site=$1&page=$3 [QSA]

所以当我输入domain1.com/site/page 时,它实际上显示了domain1.com/index.php?site=site&page=page。这很好用。

但是

我有另一个域,比如说domain2.com。我在 DirectAdmin 的同一个帐户中拥有它。当我进入 ftp 帐户并转到 domains/ 时,我看到 domain1.comdomain2.com

我想强制domain2.co.il显示domain1.com/index.php?site=domain2

我在domain2.compublic_html 中放置了相同的.htaccess 文件(对site 参数进行了细微更改)。结果是404错误。

所以问题是:如何让它按我想要的方式工作?


我还阅读了以下帖子,但我似乎无法从中找到用处。也许我只是不明白如何:

【问题讨论】:

  • 您是否有权访问 apache 的 .conf 文件?还是启用了mod_proxy 模块?或者你能启用mod_proxy吗?否则不可能。
  • 我想我可以访问这两个功能。但这对我有什么帮助?

标签: .htaccess mod-rewrite url-rewriting


【解决方案1】:

假设您的文件夹结构如下所示

/domains
    /domain1.com
    /domain2.com

您可以使用以下规则来做到这一点:

RewriteRule ^(.*)? ../domain1.com/index.php?site=domain2&q=$1 [L]

很有可能您必须使用 PHP 的 chdir() 函数才能使其在正确的目录中运行,您可以通过将 chdir() 传递给 PHP 魔术常量 __DIR__ 来做到这一点。

【讨论】:

  • RewriteRule ^(.*)? ../domain1.com/public_html/sites/index.php?site=elizur&q=$1 [L]RewriteRule ^(.*)? ../../domain1.com/public_html/sites/index.php?site=elizur&q=$1 [L](我认为 public_html 导致它上升 2 级)都会导致 400 错误(Bad Request. Your browser sent a request that this server could not understand.
  • 这很奇怪。上面的规则在我的服务器上运行良好。在这种情况下,它可能与服务器的配置有关。这特别奇怪,因为您已经打开了 FollowSymLinks。
  • 你能想到任何可能阻止这个的配置吗?
  • 不是马上。如果有的话,我可能会期待一个 Too Many Redirects 错误,所以这很令人困惑。有时间我会看看我是否不能在我自己的服务器上触发错误。
猜你喜欢
  • 1970-01-01
  • 2017-07-23
  • 2012-04-25
  • 1970-01-01
  • 2011-12-07
  • 1970-01-01
  • 2014-08-24
  • 2014-01-18
  • 2014-01-20
相关资源
最近更新 更多