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


    Require all denied

Here is another example, that prevents access to file with name config.php


    Require all denied

If you want to deny access to a folder, create a .htaccess file inside the folder with the following content

deny from all

If you want to allow whitelisted IP to access a folder, then use the following .htaccess file.

Order Allow,Deny
Allow from YOUR_IP_HERE
Deny from all
Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *