如何将https://www.example.com重定向到https://example.com [英] How to redirect https://www.example.com to https://example.com

查看:549
本文介绍了如何将https://www.example.com重定向到https://example.com的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我环顾四周,但似乎无法找到确定的解决方案.我们的域名访问者中有少数人或我们的访问者有一个小问题:

I have looked around and I can't seem to find a definitive solution for this. We are having a small problem with a few or our visitors that are typing in our domain as such:

https://www.example.com-这是一个安全警告此网站的安全证书有问题."

https://www.example.com - This is giving a security warning "There is a problem with this website's security certificate."

我们为example.com

因此,如果有人输入http://www.example.comwww.example.com,它将被重定向到https://example.com,这很好用.

So if someone types in http://www.example.com or www.example.com this gets redirected to https://example.com which works fine.

这是我目前在.htaccess文件中拥有的内容:

This is what I have currently have in my .htaccess file:

Options +FollowSymLinks 
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond %{SERVER_PORT} !^443$ [OR]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,NC,L]

推荐答案

大多数SSL证书是针对特定主机名颁发的,例如www.example.comexample.com(*.example.com也可能有通配符证书),因此可能是这种情况.

Most SSL certificates are issued for a specific hostname, e.g. www.example.com or just example.com (and there can be wildcard certificates for *.example.com too) so this might be the case.

也许在最后一个RewriteCond中将 www.子域作为可选匹配可能有助于使用户进入证书中所述的域:

Maybe making the www. subdomain an optional match in the last RewriteCond might help to get the user to the domain stated in the certificate:

RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*) [NC]

这篇关于如何将https://www.example.com重定向到https://example.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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