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

Advertisement

    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
Add a comment

Leave a Reply

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

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement