使用ssl / https将www重定向到非www的问题 [英] redirection issue in www to non www with ssl/https

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

问题描述

我有一个非www URL的SSL证书: https://domain.com

I have a SSL certificate for non www URL: https://domain.com

我知道有很多类似的问题,但似乎没有一个能解决我的问题。这是我正在尝试做的事情:

I know there are many similar question, but none of them seems to solve my problem. Here is what I am trying to do:

问题:

1) http://www.domain.com -> https://domain.com **www to non www DONE**

2) http://domain.com -> https://domain.com **http to https DONE**

3) https://www.domain.com -> https://domain.com/ **NOT DONE**
      - Getting ERROR ON Above URL number (3): Your connection is not private

到目前为止,我的.htaccess文件看起来像这样:

So far, my .htaccess file looks like so:

# www to non www
RewriteCond %{HTTP_HOST} ^www\.domain\.com [NC]
RewriteRule (.*) https://domain.com/$1 [R=301,L]

# http to https
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# https://www to htttps://

请请注意,上面的.htaccess代码适用于我的第一个和第二个问题,现在我想解决我的第三个问题

Please note that above code of .htaccess is working fine for my first and second problem, Now I want to solve my third problem

以下是我的解决方案已经尝试过:

Here are the solutions that I already tried:

htaccess强制https并将www重定向到非www,但没有其他子域

许多其他

推荐答案

尝试一下:

将www重定向到非www(使用SSL时)

To redirect www to non-www (while using SSL)

RewriteCond %{HTTP_HOST} ^www.your_domain.com$
RewriteCond %{SERVER_PORT} ^443
RewriteRule ^(.*)$ https://your_domain.com/$1 [R=301]

最后2个用于使用SSL或防止在某些页面上使用SSL时出现任何SSL错误。

The last 2 are meant for online stores using SSL or to prevent any SSL errors while using SSL on some pages.

Update1:​​

Update1:

RewriteEngine On

RewriteCond %{HTTPS} off
RewriteCond %{ENV:HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301,NE]

更新2


上使用RewriteEngine使所有http使用https:

RewriteEngine On Make all http use https:

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://xxx.yyy/$1 [L,R=301]

仅使www https使用非www https:

Make only www https use the non-www https:

RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^www[.].+$
RewriteRule ^(.*)$ https://xxxx.yyy/$1 [L,R=301]

更新3:

在此处查看此问题:

。htaccess使用SSL / HTTPS将www重定向到非www

这篇关于使用ssl / https将www重定向到非www的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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