nanadjei2's avatar

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?

0 likes
3 replies
bashy's avatar

Apache/nginx?

Can you not modify your web root?

1 like
bashy's avatar

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>
2 likes

Please or to participate in this conversation.