2016-07-28 71 views
1

我目前在我的htaccess使用此:如何避免从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。

回答

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] 

,并确保清除浏览器缓存。

+1

它的工作原理 - 我所有的感谢:o) –