Example of using. htaccess to disable access from an IP address in apache

Source: Internet
Author: User

The code is as follows:

Order Allow, Deny
Allow from all
Deny from 125.64.2.46 182.237.3.102 58.215.169.18 114.80.132.9 121.14.48.5 255.255.255.58.243.40.76 116116.23.60.197 110.75.172.81 60.215.129.75

Allow all and prohibit XXX. Change the IP address to the IP address you want to block.

Save it as. htaccess and upload it to the root directory of the website, which is usually public_html. Some programs will use this file, such as WP, and directly add it to it.

Disable ip segments

Order Allow, Deny

Allow from all

Deny from 192.168.1

Appendix: usage details

Allow and Deny can be used in apache conf Files or. htaccess Files (with Directory, Location, Files, etc.) to control access authorization for directories and Files. Order, as its name implies, is the meaning of order, so the order command can determine the order in which deny and allow work. Generally speaking, it is the final decision to decide who is at the end.
The difference between order deny, allow, and order allow and deny is obvious. The former means to check whether the deny Command exists first, and whether or not there is any allow rule. If yes, the content of the allow rule can overwrite the deny rule. For example,

Order Allow, Deny
Allow from ip1
Deny from all

The intention is to prohibit access from ip1 and allow access from all other ip addresses, but it is clear that deny is the master of the power according to the principle of who is behind and who is the largest, therefore, deny from all rejects the allow command. The correct statement should be:


Order Deny, Allow // Check Deny first, and the Allow shot Board
Deny from all // Deny command to prohibit access from all ip addresses
Allow from ip1 // Allow says only ip1 is allowed


Result: only ip1 is allowed to access the website. Access from all other ip addresses is prohibited.
In accordance with this principle, there are also the following applications.


Prohibit access from a specific ip address


Order allow, deny allow from all deny from 1.1.1.1; write the IP address to be blocked


Disable some ip addresses.


Order Deny, Allow
Deny from ip1 ip2
Or
Order Allow, Deny
Allow from all
Deny from ip1 ip2

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.