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

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

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

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

Need help with Linux Server or WordPress? We can help!

Leave a Reply

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