首页 > 解决方案 > .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

标签: apache.htaccessredirectmod-rewriteurl-rewriting

解决方案


使用您显示的示例,您能否尝试以下操作。确保您的 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]

推荐阅读