【问题标题】:How to prevent subdomains to be redirected to https如何防止子域被重定向到 https
【发布时间】:2014-03-10 04:41:39
【问题描述】:

我想将站点重定向到 https://,但我不想重定向子域。当我输入:dev.mycreditstatus.co.za 时,即使我不想这样做,它也会被重定向到 https://。

这是我的 .htaccess (public_ssl) 目前的代码:

ErrorDocument 404 https://mycreditstatus.co.za/404.php

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^imupost\.co\.za$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

.htaccess (public_html):

ErrorDocument 404 https://mycreditstatus.co.za/404.php

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/(pp5fdr) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

我应该进行哪些修改才能使其正常工作?谢谢!

【问题讨论】:

    标签: php regex .htaccess mod-rewrite redirect


    【解决方案1】:

    在您的public_html .htaccess 中,您没有任何条件将其限制在主域(假设您的子域植根于同一目录)。您需要另一个 RewriteCond 来仅匹配主域:

    ErrorDocument 404 https://mycreditstatus.co.za/404.php
    
    RewriteEngine On
    RewriteCond %{HTTPS} off
    # Only redirect to https if the main domain (no subdomain) is matched
    # case-insensitively in HTTP_HOST
    RewriteCond %{HTTP_HOST} ^mycreditstatus\.co\.za$ [NC]
    RewriteCond %{REQUEST_URI} !^/(php05142013) [NC]
    # added flags...
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

    【讨论】:

    • 哇。太感谢了。我是 regex 和 mod rewrite 的新手,所以我不太确定在 .htaccess 中放什么。再次感谢您帮助我。
    猜你喜欢
    • 2018-07-14
    • 1970-01-01
    • 1970-01-01
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 1970-01-01
    • 2016-09-25
    相关资源
    最近更新 更多