45 private links
How to block IP address via .htaccess file?
Apache 2.4 – block specific IP addresses
<RequireAll>
Require all granted
Require not ip 1.1.1.1
Require not ip 2.2.2.2
</RequireAll>
1
2
3
4
5
<RequireAll>
Require all granted
Require not ip 1.1.1.1
Require not ip 2.2.2.2
</RequireAll>
Apache older than 2.4 – block specific IP addresses
Order allow,deny
Deny from 1.1.1.1
Deny from 2.2.2.2
Allow from all
1
2
3
4
Order allow,deny
Deny from 1.1.1.1
Deny from 2.2.2.2
Allow from all
How to allow specific IP addresses to access the site via .htaccess file?
Apache 2.4 – allow specific IP addresses only
<RequireAny>
Require ip 1.1.1.1
Require ip 2.2.2.2
</RequireAny>
1
2
3
4
<RequireAny>
Require ip 1.1.1.1
Require ip 2.2.2.2
</RequireAny>
Apache older than 2.4 – allow specific IP addresses only
Order deny,allow
Deny from all
Allow from 1.1.1.1
Allow from 2.2.2.2
1
2
3
4
Order deny,allow
Deny from all
Allow from 1.1.1.1
Allow from 2.2.2.2
How to allow specific IP addresses behind CDN or CloudFlare via .htaccess file?
Apache 2.4 – allow specific IP addresses behind CDN or CloudFlare
SetEnvIF X-Forwarded-For "1.1.1.1" AllowIP
SetEnvIF X-Forwarded-For "2.2.2.2" AllowIP
<RequireAny>
Require env AllowIP
</RequireAny>
1
2
3
4
5
6
SetEnvIF X-Forwarded-For "1.1.1.1" AllowIP
SetEnvIF X-Forwarded-For "2.2.2.2" AllowIP
<RequireAny>
Require env AllowIP
</RequireAny>
Apache older than 2.4 – allow specific IP addresses behind CDN or CloudFlare
SetEnvIf X-FORWARDED-FOR 1.1.1.1 allow
SetEnvIf X-FORWARDED-FOR 2.2.2.2 allow
Order deny,allow
Deny from all
Allow from env=allow
1
2
3
4
5
SetEnvIf X-FORWARDED-FOR 1.1.1.1 allow
SetEnvIf X-FORWARDED-FOR 2.2.2.2 allow
Order deny,allow
Deny from all
Allow from env=allow
This is very basic guide and in some cases you will need to use Virtual Host configuration instead of .htaccess file. More details in official Apache2 documentation.