How to avoid redirect from subdomain in htaccess file?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-13 17:13:29

问题


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]

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.


回答1:


You can use:

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.



来源:https://stackoverflow.com/questions/38630641/how-to-avoid-redirect-from-subdomain-in-htaccess-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!