Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess:http到https重定向不起作用_.htaccess_Http_Mod Rewrite_Redirect_Https - Fatal编程技术网

.htaccess:http到https重定向不起作用

.htaccess:http到https重定向不起作用,.htaccess,http,mod-rewrite,redirect,https,.htaccess,Http,Mod Rewrite,Redirect,Https,我的.htaccess和https重定向有问题 首先,我查阅了这些链接以找到解决方案,但没有一个可以帮助我 链接列表: 当我用http加载页面时,.htaccess将我重定向到https,但当我用https加载页面时,我有一个无限循环 这是我的.htaccess代码: RewriteEngine on RewriteCond %{HTTPS} off RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} RewriteCond

我的.htaccess和https重定向有问题

首先,我查阅了这些链接以找到解决方案,但没有一个可以帮助我

链接列表:

当我用http加载页面时,.htaccess将我重定向到https,但当我用https加载页面时,我有一个无限循环

这是我的.htaccess代码:

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTP_HOST} ^(api|www|dev|stefano|sav)\.
RewriteCond %{REQUEST_URI} !^/(api|www|dev|stefano|sav)/
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^(.*)$ %1/$1 [L]

是否有人可以帮助我创建重定向条件(http到https)?

您正在退出
重写标志
您需要告诉它使用
R
标志强制重定向,并提供建议的301、302等可选状态代码

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
顺便说一下,链接到的每个示例都使用
R标志
,不确定为什么不使用确切示例:)

解决方案,如果在诸如负载平衡器之类的设备后面

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

您将退出
重写标志
您需要告诉它使用
R
标志和可选的提供状态代码强制重定向,建议使用301、302等

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
顺便说一下,您链接到的每个示例都使用
R标志显示了答案,但不确定您为什么不使用确切的示例:)

解决方案,如果在诸如负载平衡器之类的设备后面

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

我已经和这个问题斗争了好几个小时了。似乎我需要为负载平衡器后面的系统提供解决方案。也许这是因为我在我的网站上使用了Cloudflare

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

在将上述行添加到.htaccess文件后,我删除了Cloudflare上的缓存,并按原样加载了站点。

我已经为同一问题斗争了数小时。似乎我需要为负载平衡器后面的系统提供解决方案。也许这是因为我在我的网站上使用了Cloudflare

RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

在将上述行添加到.htaccess文件后,我删除了Cloudflare上的缓存,并按原样加载了站点。

可能重复的@syedmohamed这不是我要找的,但谢谢。可能重复的@syedmohamed这不是我要找的,但谢谢。它不适用于标志。我有一个错误(错误500),然后还有一个问题。你应该使用标志。apache错误日志对500错误的解释是什么?确保没有缓存旧的错误。请尝试使用标志的规则,但请清除浏览器缓存并再次测试,或者在其他浏览器中尝试。好的。你必须在负载平衡器后面,然后最有可能。很高兴你成功了。谢谢你的回答;)它不适用于旗帜。我有一个错误(错误500),然后还有一个问题。你应该使用标志。apache错误日志对500错误的解释是什么?确保没有缓存旧的错误。请尝试使用标志的规则,但请清除浏览器缓存并再次测试,或者在其他浏览器中尝试。好的。你必须在负载平衡器后面,然后最有可能。很高兴你成功了。谢谢你的回答;)