Prevent .env file from been accessed on a server.
I have a shared host website but I want to prevent .env file from been access from outside. Please how do I do it?
Apache/nginx?
Can you not modify your web root?
You can deny access to dot files with this (in .htaccess);
<FilesMatch "^\.">
Order allow,deny
Deny from all
</FilesMatch>
Or if you need access to other dot files, just protect requests starting with .env. .env~swap would be caught I think.
<FilesMatch "^\.env">
Order allow,deny
Deny from all
</FilesMatch>
Please or to participate in this conversation.