How to Restrict Access to a Folder with htaccess?

By Hardik Savani January 12, 2022 Category : .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...

Tags :
Shares