将 https 重定向到非 www,将 http 重定向到 www

编程入门 行业动态 更新时间:2024-10-23 22:26:56
本文介绍了将 https 重定向到非 www,将 http 重定向到 www的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我需要结合重定向来实现以下目标:

I need a combination of redirects to achieve the following:

将 example 重定向到 www.example,同时重定向 www.example 到 example.

To redirect example to www.example, while redirecting www.example to example.

当通过 http 访问网站时,我想强制 www 前缀做域名.

I would like to force the www prefix do the domain name when the site is accessed over http.

但是 SSL 证书只能在没有 www 的情况下工作.

However the SSL certificate only works without the www.

当通过 https 访问时,我不希望域名带有 www 前缀.

When accessed over https, I don't want the domain name to have the www prefix.

推荐答案

从 www.mysite 到 mysite 的重定向> 只能在客户端向 www.mysite 发出初始请求后发生.

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

要使此初始连接正常工作,www.mysite 上的服务器必须具有对 www.mysite 有效的证书,否则,这种连接甚至不会发生(并且服务器不会发送重定向响应).

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

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

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 and www.mysite; 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.)

当您申请另一个时,CA 颁发对 mysite 和 www.mysite 都有效的证书是很常见的,有时没有额外收费.

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

更多推荐

将 https 重定向到非 www,将 http 重定向到 www

本文发布于:2023-07-16 03:47:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117521.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   https   http   www

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!