【问题标题】:Help with htaccess redirect for subdomain帮助子域的 htaccess 重定向
【发布时间】:2011-07-04 05:06:58
【问题描述】:

我正在使用此代码将所有子域重定向到子域文件夹。 例如 test.site.com => site.com/test。

RewriteCond %{HTTP_HOST} !^www\.site\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.site\.com [NC]
RewriteRule ^(.*)$ http://site.com/%1 [L]

当我访问 test.site.com 时,它会自动重定向到文件夹 test/。我想留在域 test.site.com 并显示 test/ 文件夹的内容,而不重定向到实际文件夹。谢谢。

【问题讨论】:

  • 这是不可能的。在 mod_rewrite 中,如果 HOST_NAME 正在更改,则它必须是外部重定向,并且浏览器中的 URL 将更改以显示新的 HOST_NAME。

标签: .htaccess redirect subdomain


【解决方案1】:

您可以使用以下代码实现:

RewriteCond %{HTTP_HOST} !^www\.site\.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.site\.com [NC]
RewriteRule ^(.*)$ /%1/$1 [L]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-13
    相关资源
    最近更新 更多