如何避免从 htaccess 文件中的子域重定向?

How to avoid redirect from subdomain in htaccess file?

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

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

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

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

您可以使用:

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]

并确保清除浏览器缓存。