【问题标题】:Block access to subdirectory with .htaccess [closed]使用 .htaccess 阻止对子目录的访问 [关闭]
【发布时间】:2013-04-22 11:01:19
【问题描述】:

如何用 .htaccess 屏蔽所有子目录?

我有:

/
/subdir
/subdir/file_1
/subdir/file_2

并且想要拒绝访问

/subdir

尚未保持完全访问权限

/
/subdir/file_1
/subdir/file_2

【问题讨论】:

    标签: apache .htaccess mod-rewrite subdirectory


    【解决方案1】:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^subdir/? - [F]
    

    RewriteCond 只是一个额外的保险。

    必须激活 Apache 的 rewrite_module。

    【讨论】:

    • 有没有办法自动拒绝所有子目录?它们是动态创建的。
    • 删除 RewriteRule 正则表达式中的尾随 $ 以阻止子目录。
    【解决方案2】:
    order deny,allow
    deny from all
    allow from 12.34.56.78
    

    来源:Here

    【讨论】:

    • 这个也可以。至少对我来说更好。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-03-31
    • 2012-08-22
    • 1970-01-01
    • 2023-04-01
    • 2011-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多