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

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

问题描述

我环顾四周,我似乎无法找到一个defenant解决这个。我们正处于一个小问题,一些或我们的游客被输入在我们的领域这样:

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

我们有一个SSL设置为domain.com

所以,如果有人类型 http://www.domain.com 或www.doamin.com这得到重定向到 https://domain.com 工作正常。

这是我目前在my.htaccess文件:

 选项+了FollowSymLinks
RewriteEngine叙述上
的RewriteCond%{} SERVER_PORT 80
的RewriteCond%{} SERVER_PORT!^ 443 $ [OR]
的RewriteCond%{} HTTPS上
的RewriteCond%{HTTP_HOST} ^ WWW \。(。*)[NC]
(。*)重写规则^ $的https://%1 / $ 1 [R = 301,NC,L]
 

解决方案

编辑:

大多数SSL证书颁发给特定的主机名,例如: www.domain.com或只是domain.com(并且可以存在通配符证书* .domain.com太)所以这可能是这种情况。

<打击>也许使得 WWW。子域的的可选匹配的在过去的RewriteCond 可能有助于获得用户在域的证书中规定:

 的RewriteCond%{HTTP_HOST} ^(?:WWW \)?(。*)[NC]
 

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

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

We have an SSL set up for domain.com

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

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]

解决方案

edit:

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

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.domain.com到https://domain.com的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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