强制域的HTTPS和WWW以及子域HTACESS的HTTPS [英] Force HTTPS and WWW for domain and only HTTPS for subdomains HTACESS

查看:149
本文介绍了强制域的HTTPS和WWW以及子域HTACESS的HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试为我的网站配置此功能,但无法使用。

I've been trying to configure this for my website, but not being able to.

我用我的.htaccess上的cond来强制使用www主域名,没有子域名,但由于我有SSL,我遇到了一些问题。

I use to have a cond on my .htaccess to force www for the main domain and nothing for subdomains, but since I got a SSL, I'm having some problems.

这是一个通配符SSL。

It's a wildcard SSL.

我需要的是强制HTTPS://主域上的WWW,以及子域上的HTTPS://。

What I need is force HTTPS:// WWW on the main domain, and HTTPS:// on subdomains.

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

I.E: http://www.domain.com -> https://subdomain.domain.com

这有什么规则吗?
谢谢!

Is there any rule for that? Thanks!

编辑

现在我像Jon一样使用

Now I'm using like Jon posted

RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^domain\.com\.br$ [NC]
RewriteRule ^.*$ https://www.domain.com.br%{REQUEST_URI} [R,L]
# ---------- #
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com\.br$ [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.|)(.*)$ [NC]
RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]

事情是,当我在主域上输入HTTP://有或没有WWW时,ir强制HTTPS ://和WWW,没关系......

The thing is, when on main domain if I type HTTP:// with or without WWW, ir forces HTTPS:// and WWW, that's ok...

但是在子域名下,当我键入HTTP时,它不会强制使用HTTPS,它只会重定向到主域名。如果我将.htaccess放在子域的目录中,那就不会发生。
在我的子域dir中有一个.htaccess,如果我键入HTTP,它会强制HTTPS正常...

But on subdomain, when I type HTTP it doesn't force HTTPS, it redirects to the main domain only... that does not happen if I put a .htaccess inside the dir of the subdomain. With a .htaccess inside my subdomain dir, if I type HTTP, it forces HTTPS normally...

有什么建议吗?

推荐答案

尝试:

RewriteEngine On 

# for subdomains
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^(www\.)?domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.|)(.*)$ [NC]
RewriteRule ^.*$ https://%1%{REQUEST_URI} [R,L]

# for main domains
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com%{REQUEST_URI} [R,L]

这篇关于强制域的HTTPS和WWW以及子域HTACESS的HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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