.htaccess强制HTTPS

编程入门 行业动态 更新时间:2024-10-15 18:25:34
本文介绍了.htaccess强制HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我一直在努力寻找一种使用.htaccess强制在我的网站上使用HTTPS的方法。我尝试过的任何方法都会导致重定向循环。我找到了一个PHP替代方案,并对其进行了修改以适合我的Web服务器,但是如果有人可以帮助,我希望使用.htaccess版本。

I've been struggling for a while to find a method of using .htaccess to force HTTPS on my website. Any way I've tried has resulted in a redirect loop. I found a PHP alternative and amended it to suit my webserver, but I'd like the .htaccess equivalent if anybody could help.

if ($_SERVER['HTTP_X_FORWARDED_PROTO'] != "https") { header("HTTP/1.1 301 Moved Permanently"); $location = "" . $_SERVER[HTTP_HOST] . $_SERVER[REQUEST_URI]; header("Location: $location"); exit; }

推荐答案

您可以在您的根.htaccess:

You can use this rule in your root .htaccess:

RewriteEngine On RewriteCond %{HTTP:X-Forwarded-Proto} !https RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [L,R=301,NE]

更多推荐

.htaccess强制HTTPS

本文发布于:2023-10-31 13:52:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546278.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:htaccess   HTTPS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!