TarranJones
TarranJones

Reputation: 4242

How to configure apache return 404 for certain file extensions

I would like to be able to change the extension of any file on my server to .hide or ._ for example. If the file is visited http://www.example.com/index.hide then I would like the server to respond the same way as if the file doesn't exist.

Edit.

I would also like to make it easier to keep track of what the file extension was.

So I would actually like to prefix any extension with a _, e.g. from file.xml to file._xml

Upvotes: 0

Views: 1106

Answers (2)

Amit Verma
Amit Verma

Reputation: 41249

If you want to return a 404 error status for the .hide extension, try the follow rule:

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

To handle multiple extension, you can use a OR based pattern :

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

Upvotes: 1

cmorrissey
cmorrissey

Reputation: 8593

You can accomplish this with

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

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

Upvotes: 2

Related Questions