Alex
Alex

Reputation: 68440

Deny access to a file

If I drop a .ini file inside my site root directory, it will be visible to anyone simply by accessing

http://site.com/file.ini

Can I restrict public access to that file somehow (htaccess maybe?), but still make it accessible by my scripts?

Upvotes: 1

Views: 148

Answers (3)

shaunsantacruz
shaunsantacruz

Reputation: 8930

You could simply move that file or add this to your .htaccess:

<Files ~ "\.(ini)$">
  order allow,deny
  deny from all
</Files>

Upvotes: 1

David Thomas
David Thomas

Reputation: 253308

The easiest way to achieve this kind of security, if you don't want people to be able to directly access your web-scripts, is to put those files outside of the web-directory/web-root. That way the files within your website can still access the files via the file-paths, but people can't navigate to them with their browsers.

For example: my own private scripts reside in the 'private' folder, which is in the same directory as the /var/www/ directory, and are accessed via: include '../private/script.php';

Upvotes: 1

Ryan
Ryan

Reputation: 28187

Add this to your .htaccess file:

<files file.ini>
  order deny,allow
  deny from all
</files>

Check out the docs.

Upvotes: 6

Related Questions