Linux: Use the Rewrite rule to block the IP address of the other party

Source: Internet
Author: User

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]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.