如何将https://www.example.com重定向到https://example.com

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

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

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:

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

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

我们为example

因此,如果有人输入www.example或www.example,它将被重定向到example,这很好用.

So if someone types in www.example or www.example this gets redirected to example 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 ^(.*)$ %1/$1 [R=301,NC,L]

推荐答案

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

Most SSL certificates are issued for a specific hostname, e.g. www.example or just example (and there can be wildcard certificates for *.example 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

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

发布评论

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

>www.elefans.com

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