How to block ips via .htaccess file ?

How to block ips via .htaccess file ?

DATE – 09-05-2020

You can quickly block IP addresses from accessing your sites or specific folders using a .htaccess file. Note that the ‘.’ in front of htaccess makes this a hidden file. Please make sure your have the  ‘View Hidden Files’ option checked in your FTP program or through File Manager.

If you do not already have a .htaccess file, you can create or upload a new file and name it ‘.htaccess’. To block access to your entire site, add the .htaccess file under the public_html folder. To block access to a specific folder, add the .htaccess file within that folder.  For example, to block access to http://domain.com/dev, add the .htaccess file under the public_html/dev folder.

To block IPs, add the following lines in the .htaccess file:

order allow,deny
deny from 290.0.0.0
deny from 111.111.1.1
allow from all

This will block IPs 290.0.0.0 and 111.111.1.1 from access your files. To add more blocks, simply add more “deny from IP_ADDRESS” lines above the allow from all line.

You may find that you need to block access to a folder for everyone except you, or your developers. To block access for everyone except for specific IPs, add the following to your .htaccess file:

order allow,deny
allow from 255.0.0.0
allow from 2.2.2.2
deny from all

Thank you.

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Reply

Scroll to Top