将 HTTPS 重写为 HTTP,但活动证书不起作用

发布于 2024-12-25 21:28:37 字数 485 浏览 1 评论 0原文

当我输入 http://domain.com 时,我已为域安装了 HTTPS 证书,当我输入 https://domain.com 它不会重定向到 http。 我的 .htaccess 有

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

I have HTTPS certificate installed for domain when i type http://domain.com it works when i type https://domain.com it does not redirect to http.
My .htaccess has

Options +FollowSymlinks
RewriteEngine On

RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

笑饮青盏花 2025-01-01 21:28:37

当我输入https://domain.com时,它不会重定向到http。

您的 RewriteCond 指令将规则限制为以 www 开头的域,因此它将与您的 domain.com 测试网址不匹配。

您可以使用 https://www.domain.com 进行测试或更改如下规则

RewriteCond %{HTTPS} on
#make the www optional
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ http://%2/$1 [R=301,L]

但是,我不喜欢这个解决方案,因为我无法理解每个规则背后的意图,例如您拥有的第二条规则应该会导致无限重定向(假设这些是您的 .htaccess 中的唯一规则)。

如果您解释每条规则的意图,我将能够提供更好的答案

when i type https://domain.com it does not redirect to http.

Your RewriteCond directive limits the rule to domains starting with www so it will not match your test url of domain.com.

You can either test with https://www.domain.com or change the rule as below

RewriteCond %{HTTPS} on
#make the www optional
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ http://%2/$1 [R=301,L]

However, I don't like this solution because I cannot understand what your intention is behind each of the rules e.g. the second rule you have should cause an infinite redirect (assuming these are the only rules in your .htaccess).

If you explain what your intention is for each rule, I would be able to provide a better answer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文