我有一个非www网址的SSL证书:https://domain.com
我知道有很多类似的问题,但似乎没有一个能解决我的问题。这是我正在尝试做的:
问题:
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文件如下所示:
# 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代码对于我的第一个和第二个问题工作正常,现在我想解决我的第三个问题
以下是我已经尝试过的解决方案:
.htaccess 将 www 重定向到 non-www with SSL/HTTPS
htAccess 强制 HTTPS 并将 www 重定向到非 www,但没有其他子域
更多
试试这个:
将 www 重定向到非 www(使用 SSL 时)
RewriteCond %{HTTP_HOST} ^www.your_domain.com$
RewriteCond %{SERVER_PORT} ^443
RewriteRule ^(.*)$ https://your_domain.com/$1 [R=301]
最后 2 个适用于使用 SSL 的在线商店,或防止在某些页面上使用 SSL 时出现任何 SSL 错误。
更新1:
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
重写引擎打开让所有 http 都使用 https:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://xxx.yyy/$1 [L,R=301]
仅使 www https 使用非 www https:
RewriteCond %{SERVER_PORT} 443
RewriteCond %{HTTP_HOST} ^www[.].+$
RewriteRule ^(.*)$ https://xxxx.yyy/$1 [L,R=301]
更新 3:
在这里查看此问题:
.htaccess 将 www 重定向到 non-www with SSL/HTTPS
尝试:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www'.(.+)$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
上述规则将重定向
- http://www.example.com/
自
- https://example.com/
和
- https://www.example.com/
自
- https://example.com/
在测试之前清除浏览器的缓存。
试试这个。如果这不起作用,请检查您AllowOverride All
的站点 conf 文件。如果是None
请使其All
示例站点.conf
<Directory /var/www/directory/>
Options Indexes
AllowOverride All
Order allow,deny
allow from all
</Directory>
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ https://yourdomain.com/$1 [L,R=301]