htaccess的重定向域到https,子域名为http和WWW到非www [英] htaccess redirect domain to https, subdomain to http and www to non-www

查看:305
本文介绍了htaccess的重定向域到https,子域名为http和WWW到非www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图做到这一点:

强制HTTPS我的主要领域。

Force the https for my main domain.

http or https://www.domain.com  -> https://domain.com
http or https://domain.com  -> https://domain.com

但不适合子域

But not for subdomains

http or https://www.subdomain.domain.com -> http://subdomain.domain.com
http or https://subdomain.domain.com -> http://subdomain.domain.com

和始终在卸下了www。

And always removing the www.

现在我有:

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

这WWW重定向到非www和http到https而不是子域。子站点仍然与WWW和HTTPS。

This redirects www to non-www and http to https but not for subdomains. The subdomain remains with www and the https.

感谢

推荐答案

您可以使用这条规则:

# for main domain
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]

# for sub domain
RewriteCond %{HTTP_HOST} ^(www\.)?subdomain\.domain\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://subdomain.domain.com%{REQUEST_URI} [R=301,L,NE]

这篇关于htaccess的重定向域到https,子域名为http和WWW到非www的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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