本文介绍了.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
发布评论