ItSolutionStuff.com

How to Deny Access to a File using .htaccess?

By Hardik Savani • November 5, 2023
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...

Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

📺 Subscribe on YouTube

We Are Recommending You

Angular 13 HttpClient & Http Services Tutorial Example

Read Now →

Angular 13 CRUD Application Example Tutorial

Read Now →

How to Create Basic API in Node JS Express?

Read Now →

How to Get All Files from Folder in Node JS?

Read Now →

How to Generate QR Code in Node JS?

Read Now →

Node JS Send Email with Attachment Example

Read Now →

Node JS Express Route with Parameters Example

Read Now →

How to Get Data from Json File in Node JS?

Read Now →

Laravel 8 Mail | Laravel 8 Send Email Tutorial

Read Now →

Laravel 8 CRUD Application Tutorial for Beginners

Read Now →

Codeigniter Remove index.php form URL using htaccess

Read Now →