【问题标题】:how to configure apache mod_rewrite to redirect to non-www version with two exceptions如何配置 apache mod_rewrite 以重定向到非 www 版本,但有两个例外
【发布时间】:2016-02-06 00:16:10
【问题描述】:

我想使用 301 重定向将传入请求重定向到我们的 https:// 非 www 版本的网站。需要专门排除两个子域(webmin.domain.comnewsletter.domain.com

这是我目前所拥有的

RewriteEngine on
RewriteCond %{HTTPS_HOST} !^(newsletter|webmin)\.domain\.com$ [NC]
RewriteRule ^(.*)$ https://domain.com$1 [L,R=301]

上面的问题是,它创建了一个无限循环,因为 RewriteCond 似乎与 URL 的非 www 版本匹配。

如何正确扩展此重写规则?

【问题讨论】:

    标签: apache .htaccess mod-rewrite subdomain url-redirection


    【解决方案1】:

    尝试以下方法:

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^(?!newsletter|webmin)[^.]+\.domain\.com$ [NC]
    RewriteRule ^.*$ https://domain.com/$0 [R=301,L]
    

    【讨论】:

    猜你喜欢
    • 2019-07-31
    • 1970-01-01
    • 2010-11-09
    • 2014-07-18
    • 2012-04-14
    • 1970-01-01
    • 2017-01-17
    • 1970-01-01
    相关资源
    最近更新 更多