HTTPS重定向到非www和http到www [英] Redirect https to non-www and http to www

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

问题描述

我搜查,发现数百个相关案件,但没有完全按照我的需要。 我需要重定向的组合,请执行以下操作:

访问:

  http://mysite.com -redirected于─> http://www.mysite.com
 

  https://www.mysite.com -redirected于─> https://mysite.com
 

对于普通的 HTTP 网站,我想迫使 WWW

但SSL证书只能加www,所以 HTTPS 应的不可以有WWW。

感谢,如果有人能帮助我。

解决方案

https://www.mysite.com 重定向到 HTTPS ://mysite.com 只能发生在客户端后,已经取得了初步的要求 https://www.mysite.com

有关此初始连接到工作中,服务器 https://www.mysite.com 必须具有有效的 www.mysite证书.COM ,否则,这种连接甚至不会发生(和服务器将不发送重定向响应)。

如果你仍然想重定向,在同一台服务器上,服务器必须present的证书有效期为要服务的主机名。你应该得到两个主题备用名称的DNS条目的证书: mysite.com www.mysite.com ;这将允许您使用相同的证书,同时服务于主机(然后如果需要使用重写规则)。

(你也可以使用服务器名称指示与两个不同的证书,如果你希望客户端来支持它,但是这通常是完全不同的主机名。)

这是相当普遍的CA颁发证书的有效期为两个 mysite.com www.mysite.com 。

I searched and found hundreds of related cases, but none exactly as what I need. I need a combination of redirects to do the following:

Access to :

http://mysite.com -redirected to-> http://www.mysite.com

While:

https://www.mysite.com -redirected to-> https://mysite.com

For normal http site, I want to force www.

But the ssl certificate only works without www, so https should not have the www.

Thanks if anyone can help me.

解决方案

The redirection from https://www.mysite.com to https://mysite.com can only happen after the client has made an initial request to https://www.mysite.com.

For this initial connection to work, the server at https://www.mysite.com must have a certificate valid for www.mysite.com, otherwise, this connection won't even happen (and the server won't send a redirection response).

If you still want a redirection, on the same server, your server must present a certificate that is valid for the host names you want to serve. You should get a certificate with two Subject Alternative Name DNS entries: mysite.com and www.mysite.com; this will allow you to serve both hosts with the same certificate (and then use the rewrite rules if needed).

(You could also use Server Name Indication with two distinct certificates, if you expect the clients to support it, but that's usually for completely different host names.)

It's quite common for CAs to issue certificates that are valid for both mysite.com and www.mysite.com when you apply for one of the other, sometimes without an extra fee.

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

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