Reputation: 31
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
Reputation: 5219
Mention the below line in your .htaccess
file. It'll definitely solve your problem.
RewriteRule ^includes/ - [R=404,L,NC]
Upvotes: 3
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