ItSolutionStuff.com

How to Restrict Access to a Folder with htaccess?

By Hardik Savani • January 12, 2022
.htaccess

Hi,

In this tutorial, you will learn how to restrict access to a folder with htaccess. We will use htaccess deny access to folder. I would like to share with you how to deny access to directory htaccess. you can see how to deny access to a folder htaccess. Follow bellow tutorial step of htaccess deny access to directory.

In this post, i will show you some ways how to restrict access to directory with .htaccess file. sometime we have public directory with images and visitor can access full directory with folder path, but we can prevent this. so let's see some example and you can do it your own:

Example 1:

you can not access public directory.

.htaccess

RewriteEngine On

RewriteRule (^|/)public(/|$) - [F]

Example 2:

you can not access any directory of your app.

.htaccess

# directory browsing

Options All -Indexes

Example 3:

you can not access public directory.

.htaccess

<Directory ~ "\public">

Order allow,deny

Deny from all

</Directory>

you can see layout as bellow:

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

How to Restrict/Block IP Address using .htaccess File?

Read Now →

Laravel Connect Remote Database using SSH Tunnel Example

Read Now →

How to Generate and Add SSH Key in Gitlab?

Read Now →

How to Generate and Add SSH Key in Github?

Read Now →

How to Generate SSH Key in Ubuntu Server?

Read Now →

How to Whitelist/Allow IP Address in Apache Ubuntu?

Read Now →

How to Restrict/Block IP Address in Apache Ubuntu?

Read Now →

How to Set Up Password Authentication with Apache in Ubuntu?

Read Now →

How to Deny Access to a File using .htaccess?

Read Now →

Codeigniter Remove index.php form URL using htaccess

Read Now →