我想阻止用户通过其URL直接访问目录中的文件,但仍然希望能够通过include
或require
函数在PHP程序内使用它们。
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.
Mention the below line in your .htaccess
file. It'll definitely solve your problem.
RewriteRule ^includes/ - [R=404,L,NC]
<Files conf.inc.php>
order allow,deny
deny from all
</Files>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.