【发布时间】:2011-08-05 14:44:27
【问题描述】:
我需要允许通过 .htaccess 直接访问特定文件夹名称(和子内容),并拒绝所有其他。
首先,我当前的.htaccess 是:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
我的文件结构是,例如:
modules/
core/
_test/
publics/
file.txt
other/
_whatever/
publics/
more.txt
publics/
sub/
file.txt
other.txt
.htaccess
除了publics 文件夹中的文件和文件夹外,我无法访问任何内容。在这个例子中,我可以毫无问题地访问:
- modules/core/publics/[目录]
- modules/core/publics/file.txt
- modules/other/_whatever/publics/[目录]
- modules/other/_whatever/publics/more.txt
- 模块/其他/publics/ [目录]
- modules/other/publics/sub/ [目录]
- modules/other/publics/sub/file.txt
- modules/other/publics/other.txt
我无法访问任何文件或文件夹。
我想我们将需要正则表达式,但我不知道如何在 mod_rewrite 上使用它来像我想要的那样工作。
有什么建议吗?
【问题讨论】:
标签: .htaccess mod-rewrite