How to Deny Access to a File using .htaccess?

By Hardik Savani November 5, 2023 Category : Ubuntu Server

Hi,

Now, let's see article of How to deny access to a file in .htaccess. if you have a question about htaccess deny access to file then i will give a simple example with solution. This post will give you simple example of htaccess deny access to file extension. step by step explain htaccess deny access to all files except index.php. Let's get started with apache 2.4 htaccess deny access to file.

Here, i will give you list of examples how to deny access files using .htaccess file. sometime we have list of files that we don't want to access directly from url. you can prevent it by access url using .htaccess file. so let's see example one by one.

Example 1: Deny Access to a Single File using .htaccess

.htaccess

<Files ".env">

Order allow,deny

Deny from all

</Files>

Example 2: Deny Access to a File Extension using .htaccess

.htaccess

<Files ~ "\.php$">

Order allow,deny

Deny from all

</Files>

Example 3: Deny Access to a Folder using .htaccess

.htaccess

<Directory ~ "\app">

Order allow,deny

Deny from all

</Directory>

I hope it can help you...

Tags :
Shares