【问题标题】:Redirect a subdomain to another domain's subfolder and keep the subdomain's URL将子域重定向到另一个域的子文件夹并保留子域的 URL
【发布时间】:2014-10-09 17:00:15
【问题描述】:

我想重定向一个子域,例如 http://sub.domain.com 到另一个域的子文件夹,例如 https://unrelatedsub.otherdomain.com/domain.com/ 以及其中的所有内容,以便可以通过转到 http://sub.domain.com/u/r/l/file 来访问 https://unrelatedsub.otherdomain.com/domain.com/u/r/l/file

另外,如果可能的话,浏览器的地址栏应该显示子域的 url (http://sub.domain.com/u/r/l/file)

在寻找解决方案时,我遇到了这种可能性

RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*) https://unrelatedsub.otherdomain.com/domain.com/$1 [L,R]

但是,在这种情况下,访问 http://sub.domain.com/ 会重定向到 https://unrelatedsub.otherdomain.com/domain.com/sub/(不应该在其中)并且不会“隐藏” URL。

【问题讨论】:

    标签: .htaccess mod-rewrite redirect subdomain


    【解决方案1】:

    您正在使用 [R] 标志,这意味着外部重定向,即地址栏中的地址发生变化。如果你加载了mod_proxy,你可以使用 [P] 标志,它会导致 apache httpd 服务器代理请求,即地址栏中的 url 保持不变。

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
    RewriteRule ^(.*) https://unrelatedsub.otherdomain.com/domain.com/$1 [P]
    

    【讨论】:

    • 谢谢。但是,sub.domain.com,我被重定向到unrelatedsub.otherdomain.com/domain.com/index.cgi。关于如何摆脱 index.cgi 的任何想法?
    • 您可以在现有规则之前添加另一个 RewriteRule,例如 RewriteRule ^/?$ https://unrelatedsub.otherdomain.com/domain.com/ [P]。您在添加这些 RewriteRules 的 VHost 的 DocumentRoot 中是否有 index.cgi?
    猜你喜欢
    • 1970-01-01
    • 2016-01-03
    • 1970-01-01
    • 2012-08-13
    • 1970-01-01
    • 2015-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多