Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/257.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
Php 在htaccess中强制使用https会导致:页面为’;不能正确地重定向_Php_.htaccess - Fatal编程技术网

Php 在htaccess中强制使用https会导致:页面为’;不能正确地重定向

Php 在htaccess中强制使用https会导致:页面为’;不能正确地重定向,php,.htaccess,Php,.htaccess,我有一个数据库驱动的网站,需要在htaccess中输入一些条目。为了强制使用https,我添加了第2行和第3行,但它给出了一个错误 我试着以不同的顺序排列这两行,但结果显示错误为500。如第2行和第3行所示:“Firefox检测到服务器正在以一种永远不会完成的方式重定向对此地址的请求” .htaccess的内容是: RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.example.com/

我有一个数据库驱动的网站,需要在htaccess中输入一些条目。为了强制使用https,我添加了第2行和第3行,但它给出了一个错误

我试着以不同的顺序排列这两行,但结果显示错误为500。如第2行和第3行所示:“Firefox检测到服务器正在以一种永远不会完成的方式重定向对此地址的请求”

.htaccess的内容是:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteRule ^robots.txt robots.php [QSA,L]
RewriteCond %{REQUEST_URI} !\.(twig)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{QUERY_STRING} !^eid=(.*)
RewriteRule ^(.*) /index.php?rewrite=$1 [QSA,L]
RewriteRule ^includes/(.*) / [R=301,QSA,L]

我做错了什么?

您可以尝试以下方法:

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

这样,如果您的网站使用的端口与80不同(可能性很小,但值得一试),或者有人强迫您将url重定向到example.com而不是www.example.com,则不会受到影响。

@AlvinBakker您尝试过刷新浏览器缓存吗?