我有以下结构
index.php
.htaccess
system
- config
- classes
- modules
- module_name
- js
- css
我的目标是禁止直接访问整个“系统”文件夹,不包括资产文件夹“js”和“css”
如何使用根.htaccess中的RewriteRule
正确执行此操作?
目前我想出了如何使用RewriteRule ^system/ - [F]
禁用“系统”目录
它工作正常,但也禁用我的资产。
答案 0 :(得分:1)
您需要在阻止所有规则之前添加更具体的例外。例如,尝试以下操作:
# Exceptions: Don't block these URLs
RewriteRule ^system/modules/module_name/(js|css)/ - [L]
# Block the rest...
RewriteRule ^system/ - [F]
前面的例外只是在请求此格式的网址时阻止进一步重写。
更新:如果modules
和modules_name
目录是可变的,那么您可以将其更改为:
RewriteRule ^system/\w+/\w+/(js|css)/ - [L]
\w
是[A-Za-z0-9_]
的速记字符类。