如何使用apache .htaccess隐藏某些文件类型?

Ste*_*vko 14 apache .htaccess

自从我需要破解.htaccess文件以来已经很久了...

40x阻止访问整个站点的特定文件扩展名的最简单方法是什么?

Chr*_*lor 24

<FilesMatch "\.(htaccess|htpasswd|ini|log|sh|inc|bak)$">
Order Allow,Deny
Deny from all
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)

加载一些常见的扩展,根据需要添加更多.


Art*_*cto 12

如果你真的想要404(而不是403),你可以使用mod_rewrite:

RewriteEngine on
RewriteRule \.ext$ - [R=404]
Run Code Online (Sandbox Code Playgroud)

  • 还有`Redirect 404`,参考:[.htaccess的请求应返回404而不是403](http://stackoverflow.com/a/7945851/367456)和`RedirectMatch 404`,参考:[Make .git目录网络无法访问](http://stackoverflow.com/a/17916515/367456) - 只是在这里聚集一点. (2认同)

Mic*_*zek 5

<FilesMatch "\.ext$">
    Deny from all
</FilesMatch>
Run Code Online (Sandbox Code Playgroud)

See the Apache documentation on FilesMatch and Deny

EDIT: Artefacto makes a good point, this will return 403, not 404, if that's important for your purposes