How to deny access to a file using .htaccess?
You may need to deny access to specific files on your web server for security reasons. On the Apache web server, you can do this by using .htaccess file.
Let’s say you need to prevent anyone from accessing the file with the name .user.ini, you can create a file with the name .htaccess with the following content
1 2 3 |
<Files ".user.ini"> Require all denied </Files> |
Here is another example, that prevents access to file with name config.php
1 2 3 |
<Files "config.php"> Require all denied </Files> |
If you want to deny access to a folder, create a .htaccess file inside the folder with the following content
1 |
deny from all |
If you want to allow whitelisted IP to access a folder, then use the following .htaccess file.
1 2 3 |
Order Allow,Deny Allow from YOUR_IP_HERE Deny from all |