如何为某些文件扩展名配置apache return 404


How to configure apache return 404 for certain file extensions

例如,我希望能够将服务器上任何文件的扩展名更改为.hide._。如果文件被访问http://www.example.com/index.hide,那么我希望服务器以与文件不存在相同的方式进行响应。

编辑。

我还想让它更容易跟踪文件扩展名是什么。

因此,我实际上想在任何扩展名前面加一个_,例如从file.xmlfile._xml

您可以使用实现这一点

<FilesMatch "('.(hide|_)|~)$">
    ## Apache 2.2
    Order allow,deny
    Deny from all
    Satisfy All
    ## Apache 2.4
    # Require all denied
</FilesMatch>

如果您想为.hide扩展返回404错误状态,请尝试以下规则:

RewriteEngine on
RewriteCond %{THE_REQUEST} /.+'.hide [NC]
RewriteRule ^ - [R=404,L]

要处理多个扩展,可以使用基于OR的模式:

RewriteCond %{THE_REQUEST} /.+'.(hide|foo|bar|_) [NC]