apache - 当我在 HTTPS (.htaccess) 上访问一个没有结束斜杠的文件夹时出现奇怪的行为
问题描述
我有一个托管在真实主机上的网站(使用Apache 2.4.46
和Php 7.4
(64 位)托管 linux),以及在我的 PC 上托管的网站(使用Apache 2.4.48
(OpenSSL 1.1.1k)和Php 8.07
(64 位)托管 Windows 10)。
首先我必须说,在真正的托管(托管 linux)上,我必须使用不同的.htaccess
配置:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
在我的电脑(托管窗口)上,我必须使用另一种.htaccess
配置:
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
所以我将两种配置组合成一个规则集:
################################################################################
########################### Fix for Loading Resources ##########################
################################################################################
Options -Multiviews
################################################################################
############################### Force to use HTTPS #############################
################################################################################
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
################################################################################
########################## Set Security Header Options #########################
################################################################################
<IfModule mod_headers.c>
Header always set Content-Security-Policy "upgrade-insecure-requests;"
Header set X-Content-Type-Options "nosniff"
Header append X-Frame-Options "SAMEORIGIN"
Header set X-XSS-Protection "1; mode=block"
Header unset X-Powered-By
</IfModule>
################################################################################
########################## Prevent Caching for CSS/JS ##########################
################################################################################
<FilesMatch "\.(?i:css|js)$">
<IfModule mod_expires.c>
ExpiresActive Off
</IfModule>
FileETag None
<IfModule mod_headers.c>
Header unset ETag
Header unset Pragma
Header unset Cache-Control
Header unset Last-Modified
Header set Pragma "no-cache"
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Expires "Thu, 1 Jan 1970 00:00:00 GMT"
</IfModule>
</FilesMatch>
在我的 PC ( localhost
) 上,当我访问文件夹时"gallery"
没有结束斜杠时,我可以看到:
GET https://localhost/gallery [HTTP/2 301 Moved Permanently 0ms]
GET https://localhost/gallery/ [HTTP/2 302 Found 201ms]
在我的真实主机上,当我访问"gallery"
没有结束斜线的文件夹时,我可以看到:
GET https://www.example.it/gallery [HTTP/2 301 Moved Permanently 116ms]
GET http://www.example.it/gallery/ [HTTP/1.1 301 Moved Permanently 73ms]
GET https://www.example.it/gallery/ [HTTP/2 302 Found 84ms]
如您所见(在firefox consolle
(CTRL + Shift + I)中),在localhost
我将所有记录标记为HTTP/2
时,在真实主机上我将一条记录标记为HTTP/1
。这意味着没有HTTPS
。
我没有.htaccess
内部文件夹"gallery"
或其他文件夹,除了root
我发布的.htaccess
.
我能做些什么来修复它?我想要一个.htaccess
适用于两个系统并适用于所有文件夹的规则,HTTP/2
即使没有结尾斜杠,我也可以完全访问所有文件夹。
PS:在我拥有HTTP/2
和SSL
(真HTTPS
)的两个系统上。
谢谢。
解决方案
推荐阅读
- jsonschema - JSONSchema 外键检查
- typescript - 嵌套对象内的返回类型联合
- mongodb - MongoDB——存储策略
- sql - sql中是否存在将一个表的缺失数据填充到另一个表的连接?
- angular - 清除 Angular 中的表单值
- numpy - 在 numpy 数组中设置的布尔索引
- mongodb - 如何在mongodb的双字段中存储null
- google-chrome - 如果框架为空白,则上下文单击在 iframe 中无法用于 chrome 扩展
- javascript - jQuery.eCalendar() - 用于事件循环
- android - 使用“重建项目”与“运行”时不同的 APK 内容