Menu Close

How to deny IP addresses by .htaccess

To ban a single IP address from accessing your Website, add following code to the .htaccess file in the root directory of your html file. If you donot have .htaccess file in your root directory, you can create one. FTP and file manager can help you to create .htaccess file. Please remember the “.” before htaccess. “.” means hidden file.

order allow,deny
deny from
deny from 221.138.7
allow from all

The above lines tell the Apache Web Server to block visitors from the IP address ‘’ and ‘221.138.7’, note the second IP address is missing the fourth set of digits, this means any IP address which matches the firth three set of digits will be blocked, e.g. ‘’ , ‘’ till ‘’ would be blocked.

If you want to block every visitors except you to visit your website or any directory. This is especially useful for your wordpress admin directory, and other kind of content management software admin directory such as phplinkdirectory admin directory, and vbulletin forum admin directory. You can add following code to your root directory or the the limited directory:

order allow,deny
allow from
deny from all

‘’ is your IP address. Above code is very useful to protect your admin folder. If you donot know your IP address, you can ask google. Just in google chrome in the browser line and click ” whay is my IP address “, google will tell you. You can also ask our website,