Use .htaccess to limit IP address

Sometimes, in order to avoid so many useless visit to your server, which may cause a waste of resource and slow response, it is necessary to limit IP address.

Create a file named .htaccess in the web directory, then add the following contents according to your purpose.

Block IP address

Block certain IP address

order allow,deny
deny from 222.222.222.222
allow from all

Block several IP addresses, just several deny from will be OK

order allow,deny
deny from 222.222.222.222
deny from 111.111.111.111
deny from ***.***.***.***
allow from all

Block one entire IP period

order allow,deny
deny from 222.222.222
allow from all

Block part of one entire IP period

order allow,deny
deny from 222.222.222.100/200
allow from all

Allow IP address

Allow certain IP address

order allow,deny
allow from 222.222.222.222
deny from all

Allow several IP addresses, just several allow from will be OK

order allow,deny
allow from 222.222.222.222
allow from 111.111.111.111
allow from ***.***.***.***
deny from all

Allow one entire IP period

order allow,deny
allow from 222.222.222
deny from all

Allow part of one entire IP period

order allow,deny
allow from 222.222.222.100/200
deny from all

Block certain website

If you find some websites copy your blog, just block them!

order allow,deny
deny from .copy.com [this is website]
allow from all

This will block the visit from copy.com website, there is a dot before copy.com, this will block all its website (including second-level domain).

Reference

.htaccess根据IP地址限制访问

CHENYUAN

CHENYUAN
Pursuing the dream and the best future

CHENYUAN Blog Homepage

因为不想遗忘! 在这个信息大爆炸的年代,最重要的是对知识的消化-吸收-重铸。每天学了很多东西,但是理解的多少,以及能够运用多少是日后成功的关键。作为一个PhD,大脑中充斥了太多的东西,同时随着年龄的增长,难免会忘掉很多事情。所以只是为了在众多教程中写一个自己用到的,与自己...… Continue reading