简体   繁体   English

仅将www根目录而不将子目录的http重定向到https

[英]Redirect http to https for only www root and not subdirectories

I am trying to redirect a website to https. 我正在尝试将网站重定向到https。 I used 我用了

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

I have www.example.com.au and these redirected fine; 我有www.example.com.au并且这些重定向很好; however, I also have mobile.example.com.au which i don't want to redirect. 但是,我也有mobile.example.com.au ,我不想重定向。 How can I redirect one without the other? 如何重定向一个而不另一个?

Just add another condition to allow this rule for main domain only: 只需添加另一个条件,以使该规则仅适用于主域:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com\.au$ [NC]
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM