如何避免从htaccess文件中的子域重定向? [英] How to avoid redirect from subdomain in htaccess file?

查看:46
本文介绍了如何避免从htaccess文件中的子域重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前在htaccess中使用它:

I am currently using this in my 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。

But it has the unfortunate effect of redirecting every call to the mobile site (m.example.com) to the main page. How do I make an exception to m.example.com? I don't know how to setup RewriteRule correctly.

推荐答案

您可以使用:

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]

并确保清除浏览器缓存。

And make sure to clear your browser cache.

这篇关于如何避免从htaccess文件中的子域重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆