Annanta
Annanta

Reputation: 31

How do you prevent direct access to a file in Apache?

I'd like to stop the user from directly accessing the files in a directory via their URL, but would still like to be able to use them inside a PHP program via include or require functions.

Upvotes: 2

Views: 1607

Answers (3)

Ipsita Rout
Ipsita Rout

Reputation: 5219

Mention the below line in your .htaccess file. It'll definitely solve your problem.

RewriteRule ^includes/ - [R=404,L,NC]

Upvotes: 3

Maccath
Maccath

Reputation: 3966

It is possible to put a .php file outside of the public_html folder. For example, if your public_html folder is at /my/domain/public_html/ you could put your PHP files in /my/domain/php_files/ and still access it from scripts within the public_html folder by using absolute or relative paths, but since it is outside of the public folder it will not be accessible over the web.

Keeping files outside of the public document folder is recommended best practice for configuration files etc. for security reasons.

Upvotes: 3

Konstantin
Konstantin

Reputation: 566

<Files conf.inc.php>
order allow,deny
deny from all
</Files>

Upvotes: 0

Related Questions