【问题标题】:Redirect subdomain into top-level domain's folder将子域重定向到顶级域的文件夹
【发布时间】:2010-11-30 05:28:03
【问题描述】:

这就是我想要做的。

当您键入 m.example.com 时,我希望用户被重定向到 example.com/m/,但我希望保留地址栏中的 url如果可能,请使用 m.example.com。

【问题讨论】:

    标签: .htaccess redirect subdomain


    【解决方案1】:

    您可以使用 mod_rewrite 和 mod_proxy 做到这一点:

    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^m\.example\.com$
    RewriteRule ^ http://example.com/m%{REQUEST_URI} [L,P]
    

    【讨论】:

    • @JackSpairow 使用R=301 而不是P
    • 在 mod_proxy 中是否需要为此进行任何特定设置?
    • 即使子域 m.example.com 不存在,有没有办法做到这一点。
    • @GovindBalaji 域必须由 DNS 成功处理以指向正确的 IP 地址,并且必须被 Web 服务器接受/映射。
    • @Gumbo 在我的虚拟主机中,没有子域是有限的。我可以使用 htaccess 来解决这个问题吗?
    【解决方案2】:

    只需将子域的根目录设置为 example.com/m/。然后就没有重定向了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-13
      • 1970-01-01
      相关资源
      最近更新 更多