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

Php 如何为某些文件扩展名配置apache return 404,php,apache,.htaccess,Php,Apache,.htaccess,例如,我希望能够将服务器上任何文件的扩展名更改为.hide或。。 如果文件被访问http://www.example.com/index.hide然后我希望服务器以与文件不存在时相同的方式响应 编辑 我还想使跟踪文件扩展名变得更容易 因此,我实际上想在任何扩展名前面加上。,例如从文件.xml到文件 <FilesMatch "(\.(hide|_)|~)$"> ## Apache 2.2 Order allow,deny Deny from all Sa

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

编辑

我还想使跟踪文件扩展名变得更容易


因此,我实际上想在任何扩展名前面加上
,例如从
文件.xml
文件

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

    ## Apache 2.4
    # Require all denied
</FilesMatch>

##Apache2.2
命令允许,拒绝
全盘否定
满足所有
##Apache2.4
#要求全部拒绝

您可以使用

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

    ## Apache 2.4
    # Require all denied
</FilesMatch>

##Apache2.2
命令允许,拒绝
全盘否定
满足所有
##Apache2.4
#要求全部拒绝

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

RewriteEngine on
RewriteCond %{THE_REQUEST} /.+\.hide [NC]
RewriteRule ^ - [R=404,L]
要处理多个扩展,可以使用基于或的模式:

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

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

RewriteEngine on
RewriteCond %{THE_REQUEST} /.+\.hide [NC]
RewriteRule ^ - [R=404,L]
要处理多个扩展,可以使用基于或的模式:

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