【问题标题】:.htaccess Redirect sub.DomainA to DomainB/Subdir Without Changing URL.htaccess 将子域重定向到域/子目录而不更改 URL
【发布时间】:2015-02-25 01:11:48
【问题描述】:

我已经在网上彻底搜索了这个问题的答案,没有任何运气。

我正在尝试编写执行以下操作的 htaccess 重定向:

重定向:

subdomain.DomainA.com

到:

DomainB.com/subdir/

但不更改地址栏中显示的 URL,并保持访问 subdomain.DomainA.com 的直接链接

所以subdomain.DomainA.com/link/1000 变成了DomainB.com/subdir/link/1000

这是我去过的最接近的地方,但我还不能确定。

RewriteEngine on
RewriteCond %{HTTP_HOST} ^subdomain.DomainA.com$
RewriteRule ^(.*)$ http://DomainB.com%{REQUEST_URI} [P]

我也尝试过RewriteRule ^(.*)$ http://DomainB.com/subdir%{REQUEST_URI} [P],但由于某种原因这会返回 subdomain.DomainA.com/subdir :(

任何帮助将不胜感激!

【问题讨论】:

标签: php apache .htaccess mod-rewrite redirect


【解决方案1】:

如上所述,当您使用 [P] 时,您实际上是在调用 mod_proxy。您必须先使其工作,然后才能在重写规则中使用它。事实上,您是否为您尝试访问的主机启用了代理?

http://httpd.apache.org/docs/current/mod/mod_proxy.html#proxy

<Proxy http://DomainB.com>
   Require all granted
</Proxy>

您可能会增加您的 LogLevel(和/或)RewriteLogLevel 以帮助调试它为什么不工作(我不记得代理拒绝是在重写日志中还是只是简单的错误日志)

【讨论】:

  • mod_proxy.so 确实已加载到 DomainB 的 Apache 中。我应该把这个放在哪里?在 subdomain.DomainA.com 的 .htaccess 中?
  • 我之所以调用 [P] 标志只是因为这是我在其他一些示例中看到的,但我不确定这是否有必要。也许还有其他方法?
  • 这是在不重定向用户的情况下重写到另一个外部 url 的方法。 (您将使用 [R])
  • 这个应该在domainA的htaccess中是的。您告诉 apache 允许为每个人代理对 domainB.com 的请求(一种开放代理,但仅适用于 1 个域)。
猜你喜欢
  • 2014-01-17
  • 2017-07-23
  • 2015-12-01
  • 2015-06-22
  • 2017-02-02
  • 1970-01-01
  • 2015-04-03
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多