In many cases, access from an IP address can easily cause a CPU usage of 100% (for example, fixed crawling by some search engines and massive collection sites by others ), at this time, we need to use some effective means to block the IP address of the other party so that it cannot consume server resources. There are many methods to block IP addresses, if the Rewrite module is installed on your Web server, you can use the Rewrite rule to block the IP address of the other party.
1. For example, we direct a specific IP address to the baidu homepage and add code to the. htaccess file in the root directory of the website:
RewriteCond % {REMOTE_ADDR} 123.123.123.123 [NC]
RewriteRule ^ (. *) $ http://www.baidu.com/#1 [R = 301]
Replace 123.123.123.123 with the IP address you want to restrict.
2. To implement multiple IP addresses, write as follows:
RewriteCond % {REMOTE_ADDR} 123.123.123.123 [OR]
RewriteCond % {REMOTE_ADDR} 124.124.124.124 [NC]
RewriteRule ^ (. *) $ http://www.baidu.com/#1 [R = 301]