gpt4 book ai didi

.htaccess - .htaccess-尝试强制使用https时“重定向过多”

转载 作者:行者123 更新时间:2023-12-04 02:30:24 26 4
gpt4 key购买 nike

我试图强制我的根域的子文件夹(/ bbb /)始终显示为https。我的.htaccess文件还负责页面的扩展。

我已经将.htaccess文件放在我的/bbb/文件夹中,但是当我尝试强制连接到https时,出现“重定向过多”的情况,否则一切正常。

我的代码有什么问题?

Options +FollowSymLinks -MultiViews
Options +Indexes
AcceptPathInfo Off
RewriteEngine on
RewriteBase /

ErrorDocument 404 https://example.co.uk/404page/404.html

#Force from http to https
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} !^bbb.example.co.uk/$
RewriteRule ^(.*)$ https://bbb.example.co.uk/$1 [R=301]

#take off index.html
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} ^(.*/)index\.html$ [NC]
RewriteRule . http://www.%{HTTP_HOST}%1 [R=301,NE,L]

## hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [L]

## hide .html extension
# To externally redirect /dir/foo.html to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.html [NC]
RewriteRule ^ %1 [R,L,NC]

## To internally redirect /dir/foo to /dir/foo.html
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^ %{REQUEST_URI}.html [L]

最佳答案

问题在于此规则:

#Force from http to https
RewriteCond %{SERVER_PORT} 80
RewriteCond %{HTTP_HOST} !^bbb.example.co.uk/$
RewriteRule ^(.*)$ https://bbb.example.co.uk/$1 [R=301]


将此规则更改为:

#Force from http to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =bbb.example.co.uk
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301]


由于开始使用 !导致条件反转,并且末尾有一个额外的斜杠(永远不会匹配),因此使条件始终返回true。

在测试之前,请确保清除浏览器缓存。

关于.htaccess - .htaccess-尝试强制使用https时“重定向过多”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36748110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com