How to restrict access to your website
Have you ever created a website that has only access from specific IP Address? Or are you planning to create website service that can be access by specific IP Address?
If so, in this tutorial I will help you on how you are going to add restriction on you website.
Prerequisite
- Web Server with mod_rewrite enabled
- Basic knowledge or idea about .htaccess
What is .htaccess file?
A brief information about .htaccess file, it is a web server configurations file that can controls incoming web service request.
Create your .htaccess file
On your main website folder create .htaccess file. On your .htaccess file add the following codes:
# BEGIN Blacklist Undesired IPs (User and Bots)<Limit GET POST PUT>
ErrorDocument 403 /403.html
order deny,
allow deny from all
allow from <allowed IP Address>
</LIMIT> # END Blacklist Undesired IPs (User and Bots)
You just need to specify the IP Address you want to allow to access your website.
For ErrorDocument 403 you can specify the view which user will see if they don’t have access to your website. If you already have 403.html file you can just leave it as is.
If you have any questions, just drop your comment below. I’ll be much willing to help.