简体   繁体   English

htaccess重定向https:// www。 (https://www.example.com)到非www(https://example.com)

[英]htaccess redirect https://www. (https://www.example.com) to non www (https://example.com)

I'm trying to redirect all requests from http to https and all requests from www. 我正在尝试将所有请求从http重定向到https和所有请求从www重定向。 to non www (https://) but no matter what i try it is not working. 到非www(https://),但是无论我尝试什么都不起作用。 Specifically the redirect from https://www.example.com to https://example.com is not working. 特别是从https://www.example.comhttps://example.com的重定向无效。 Everything else works fine. 其他一切正常。 I've tried many different ways i found here on stackoverflow and other posts on the internet but none of them are working for me. 我已经尝试过在stackoverflow和互联网上的其他帖子中找到的多种不同方式,但是没有一种对我有用。 When i go to https://www.example.com i get a certificate warning cause the certificate is issued to https://example.com . 当我转到https://www.example.com时,我收到证书警告,原因是证书已颁发给https://example.com I'm really giving up on this one as i've tried it for two days now ... 我真的已经放弃了这个,因为我已经尝试了两天了...

Maybe i'm doing something completely wrong or it is something else i forgot. 也许我做的事情完全错误,或者我忘记了其他事情。 Help is much appreciated, thank you. 非常感谢您的帮助,谢谢。

This is the code i'm using right now 这是我现在正在使用的代码

RewriteEngine on
# www -> https without www
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
# http -> https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]

Cheers 干杯

Arkascha had the right answer so i'm quoting his comment: Arkascha的回答是正确的,因此我引用了他的评论:

Request rewriting cannot somehow magically get you around the client side certificate validation. 请求重写无法以某种方式神奇地使您绕过客户端证书验证。 The initial requests goes to www.example.com. 最初的请求转到www.example.com。 If the client cannot validate the specified certificate for that request it issues an error to the user. 如果客户端无法验证该请求的指定证书,它将向用户发出错误。 There is no way around that. 没有办法解决。 You either need an additional certificate for that host or a wildcard certificate. 您需要该主机的其他证书或通配符证书。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 解析 http://www.example.com 以通过 htaccess 永久重定向到 https://example.com - Resolving http://www.example.com to permanently redirect to https://example.com via htaccess 全部重定向到 https://www.example.com - Redirect all to https://www.example.com Apache2 使用虚拟主机将 https://example.com 重定向到 https://www.example.com - Apache2 redirect https://example.com to https://www.example.com with vhosts 如何将https://example.com/重定向到https://www.example.com/ - How to Redirect https://example.com/ to https://www.example.com/ 如何将 https://www.example.com/aaa 重定向到 https://example.com/aaa/ - how to redirect https://www.example.com/aaa to https://example.com/aaa/ 如何使 htaccess 强制 https 用于 www.example.com 和 example.com 但没有其他子域 - how to make htaccess force https for www.example.com and example.com but no other subdomains http://example.com不会重定向到https://www.example.com - http://example.com would not redirect to https://www.example.com 如何将 http://www.example.com 重定向到 https://example.Z4D236D9A2D102C5ZFE6AD1Cware - How to redirect http://www.example.com to https://example.com with middleware 将* .example.com和example.com重定向到HTTPS的www.example.com时出现问题 - Problem with redirecting *.example.com & example.com to www.example.com for HTTPS www.example.com没有重定向到HTTPS - www.example.com not redirecting to HTTPS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM