How to Restrict Access to a Folder with 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
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Restrict/Block IP Address using .htaccess File?
- Laravel Connect Remote Database using SSH Tunnel Example
- How to Generate and Add SSH Key in Gitlab?
- How to Generate and Add SSH Key in Github?
- How to Generate SSH Key in Ubuntu Server?
- How to Whitelist/Allow IP Address in Apache Ubuntu?
- How to Restrict/Block IP Address in Apache Ubuntu?
- How to Set Up Password Authentication with Apache in Ubuntu?
- How to Deny Access to a File using .htaccess?
- Codeigniter Remove index.php form URL using htaccess