英文:
Apache HTTPD - recursively deny specific file extensions and/or subdirs?
问题
在Apache 2.4的htdocs
文件夹中,有一种复杂的目录和子目录结构。
是否可以创建一个单个的顶层.htaccess
文件,以拒绝特定文件扩展名(例如.bak
)和/或禁止进入特定目录名称(例如.git
)整个子目录结构?
例如,当请求以下文件时,我想用HTTP 403 Forbidden
作出响应:
htdocs/index.html.bak
htdocs/aaa/bbb/ccc/login.php.bak
htdocs/foooooooo/.git/subdir/some_pic.png
如果无法通过.htaccess
实现,也许可以通过httpd.conf
实现吗?
谢谢!
英文:
I have an Apache 2.4 web server, and in its htdocs
folder, there is a complicated structure of directories and subdirectories.
Is it possible to create a single, top-level .htaccess
file that would deny specific file extensions (e.g. .bak
)
and/or traversing into specific directory names (e.g. .git
)
for the whole subdirectory structure?
E.g., I would like to respond with HTTP 403 Forbidden
when requested:
htdocs/index.html.bak
htdocs/aaa/bbb/ccc/login.php.bak
htdocs/foooooooo/.git/subdir/some_pic.png
If not via .htaccess
, then perhaps this can be achieved via httpd.conf
?
Thanks!
答案1
得分: 1
感谢!我最终得到了以下的.htaccess
配置:
RewriteEngine On
RewriteRule \.bak$ - [F]
RewriteRule (^|/)\.git($|/) - [F]
当然,在httpd.conf
中,这一行必须首先取消注释:
LoadModule rewrite_module modules/mod_rewrite.so
英文:
Thanks! I ended up with the following .htaccess
:
RewriteEngine On
RewriteRule \.bak$ - [F]
RewriteRule (^|/)\.git($|/) - [F]
Of course, this line in httpd.conf
has to be uncommented first:
LoadModule rewrite_module modules/mod_rewrite.so
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论