【问题标题】:How to avoid redirect from subdomain in htaccess file?如何避免从 htaccess 文件中的子域重定向?
【发布时间】:2016-07-28 16:22:20
【问题描述】:

我目前在我的 htaccess 中使用它:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

但不幸的是,它将每次调用移动站点 (m.example.com) 重定向到主页。如何对 m.example.com 进行例外处理?我不知道如何正确设置 RewriteRule。

【问题讨论】:

    标签: .htaccess redirect subdomain


    【解决方案1】:

    你可以使用:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
    
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} !^m\. [NC]
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
    

    并确保清除浏览器缓存。

    【讨论】:

      猜你喜欢
      • 2021-11-17
      • 1970-01-01
      • 2012-01-18
      • 2011-10-14
      • 2017-07-07
      • 2013-01-20
      • 1970-01-01
      • 2013-12-03
      • 1970-01-01
      相关资源
      最近更新 更多