apache - .htaccess - 拒绝除 index.php 和当前目录之外的所有内容 ./
问题描述
.htaccess
“拒绝所有”除 index.php 和当前目录之外的所有文件 ./
大家好,我正在尝试一个必须工作但我不知道该怎么做的愚蠢事情。
通过这种方式,我可以为除 index.php 页面以外的所有文件(图像和 CSS 也)向用户提供 403 错误
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
<Files /index.php>
Order Allow,Deny
Allow from all
</Files>
但我还想将当前目录 [./] 添加到允许的搜索中
怎么做?请
因为如果我从浏览器搜索此 URL --> https://hostname.com/403dir/它会给我 403 错误,我不想要它。
TNKS
解决方案
使用您显示的示例,您能否尝试以下操作。确保您的 htaccess 文件位于根路径中(除了 403dir 路径不在 403dir 内)。
请确保在测试您的 URL 之前清除您的浏览器缓存。
RewriteEngine ON
RewriteCond %{REQUEST_URI} !^/403dir/?$ [NC]
RewriteCond %{REQUEST_URI} !index\.php$ [NC]
RewriteRule ^ - [F,L]
或按如下方式使用单个条件本身,请确保您一次使用上述解决方案或以下解决方案。
RewriteEngine ON
RewriteCond %{REQUEST_URI} !(^/403dir|index\.php$) [NC]
RewriteRule ^ - [F,L]
推荐阅读
- python - 无法使交互式 matplotlib 绘图工作(不在 Jupyter 模式下时)
- c++ - 为什么 std::map 没有 FindOrNull 方法
- c++ - Qt Creator + CMake 不解析文件
- c# - 是否可以在调试时声明 C# 方法/函数?
- python - 使用 pandas 压缩一个数据帧,使用一个数据帧中的值填充一个新的数据帧
- string - 优化速度和字符串的问题
- bash - 使用 sed 追加带有 alt 字符的行
- ajax - Ajaxinate Endless scolling 已停止产品快速查看工作
- jupyter - 如何在通过 mybinder.org 构建时将 jupyter 实验室文档标记为受信任,以便自动运行所有代码单元
- rest - 为整个应用程序设置一个端点的目的是什么?