How to restrict users from accessing files & directory level(Protect directory) using .htaccess
- Date: Jan 12, 2010
- Author: Rakshit Patel
- Comments: 4
- Tags: .htaccess tricks, Ban IP from access, Ban IP range from access, Deny access from directory, Helpful tips, Magic Tricks, Protect folders and files, Protect using .htaccess, Restrict users folder access
- Categories: .htaccess, Helpful Tips and Tricks
Today i faced a situation where i have to restrict or deny users from accessing files and folders of my web application directly by entering URL in browser which contain very important contents like images,pdfs,docs,etc. For this what i need to do is to protect the files and folders(directory) which contains images,pdfs and docs. We can restrict users from accessing files,folders and subfolders by using .htaccess(Hyper Text Files).
Using .htaccess, you can restrict or deny access to individual files and folders. Below is the example how to restrict or deny users from accessing images folder. Make a .htaccess files and upload it in images folder. So this will be effective only for images folder(not for whole site).
# This will restrict all users from accessing images folder directly from web.
deny from all
If you would like to ban only one IP or range of IP than look at the below rules.
# Restrict only 192.168.0.1 IP user.
deny from 192.168.0.1
allow from all
# Restrict an IP range from 192.168.0.0 to 192.168.0.10
deny from 192.168.0.0/10
allow from all