Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide certain file type using apache .htaccess?

Its been a long time since I've needed to crack open an .htaccess file...

What is the simplest way to 40x prevent access to a specific file extension through out the entire site?

like image 542
Stevko Avatar asked May 18 '10 18:05

Stevko


People also ask

What htaccess file contains?

. htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

What should htaccess file permissions be?

What permissions should the file have? 644 permissions are usually fine for an . htaccess file. When you create the file on the server, it should already have these permissions set, so there is most likely nothing to change.


2 Answers

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

Loaded with some common extensions, add more as you need.

like image 60
Chris Lawlor Avatar answered Oct 25 '22 15:10

Chris Lawlor


If you really want a 404 (and not a 403), you can use mod_rewrite:

RewriteEngine on
RewriteRule \.ext$ - [R=404]
like image 20
Artefacto Avatar answered Oct 25 '22 14:10

Artefacto