【问题标题】:PHP .htaccess point subdomain to directory in root without redirectPHP .htaccess 将子域指向根目录,无需重定向
【发布时间】:2017-02-22 18:54:08
【问题描述】:

我需要将子域指向(而不是重定向)到根域中的目录。例如我有以下域:

https://test.example.com

我希望它指向目录:

https://example.com/apple

这需要在不更改子域的 URL 的情况下发生。它还需要包含任何 URL 参数,例如:

https://test.example.com/hello-world

应该指向(而不是重定向)到:

https://example.com/apple/hello-world

在我的.htaccess 文件中(在子域的根目录中)我有:

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^test\.example\.com$
RewriteCond %{REQUEST_URI} !^/apple$
RewriteRule ^(.*)$ https://example.com/apple/$1

这可行,但它会重定向。关于如何在不使用mod_proxy 的情况下将子域指向该目录而不重定向的任何建议?

【问题讨论】:

标签: php .htaccess mod-rewrite


【解决方案1】:

试试下面的规则,我假设两个域都指向同一个位置。

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^test\.example\.com$
RewriteRule ^(.*)$ apple/$1 [L]

【讨论】:

  • 谢谢。我更新了我的问题,我可能无法打开 mod_proxy(它是一个共享服务器)。
猜你喜欢
  • 2017-06-26
  • 2011-08-05
  • 1970-01-01
  • 2014-08-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-12
  • 1970-01-01
相关资源
最近更新 更多