【问题标题】:redirect specific subdomain for many domains to single domain将许多域的特定子域重定向到单个域
【发布时间】:2016-06-13 23:34:55
【问题描述】:

我们正在尝试将许多域但特定子域重定向到单个域,所有域 doc root 都在一个文件夹中,因此在该根文件夹中使用 .htaccess 应该对所有域都是递归的,例如

/home/user/public_html/.htaccess

/home/user/public_html/domain1/
/home/user/public_html/domain2/
/home/user/public_html/domain3/

我们想将邮件.* 重定向到https://server.domain.com:2096/

RewriteEngine On
RewriteRule ^mail(.*)$ https://server.domain.com:2096/ [R=301]

假设它需要更复杂,但在为域本身使用通配符时找不到类似的东西

【问题讨论】:

    标签: apache .htaccess redirect mod-rewrite


    【解决方案1】:

    你需要使用RewriteCond %{HTTP_HOST}来匹配域名:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^mail [NC]
    RewriteRule ^ https://server.domain.com:2096%{REQUEST_URI} [R=301,L,NE]
    

    【讨论】:

    • 谢谢,愚蠢的问题,是否需要在 Apache 配置中有一个虚拟主机才能使子域工作?
    • 没错,你也可以在vhost中使用通配符。
    猜你喜欢
    • 2023-03-27
    • 1970-01-01
    • 2015-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多