开发者

How could I redirect or deny users from a particular country with my htaccess file?

I looked at countryipblocks.net, and need to clarify...

If I want to block users from, say, Andorra from visiting my site, what exactly needs to be added to my (already existing) .htaccess file?

Do I need to simply add this block of text to my .htaccess?

<Limit GET HEAD POST>
orde开发者_运维技巧r allow,deny
deny from 85.94.160.0/19
deny from 91.187.64.0/19
deny from 194.117.123.178/32
deny from 194.158.64.0/19
deny from 195.112.181.196/32
deny from 195.112.181.247/32
allow from all
</LIMIT>

On the other hand, if I want to redirect users from, say, Croatia, from http://mywebsite.com to http://google.com or a landing page, what exactly needs to be added to my .htaccess file?

Finally - how would "deny" appear to the user being denied access?

Thanks.


Visitors who are within a IP range that is banned by deny will be served with a 403 error. If you want to them to see a nice page, instead of the standard Apache error, then you will need something like

ErrorDocument 403 /errors/403.html

in your .htaccess file. It is fairly easy to check rules based on IP addresses are working in your .htaccess by setting the blocked IP to be 127.0.0.1 (i.e. localhost); when you then look at the page in question on localhost, you should see the result of the page being blocked.

In answer to your question about redirecting users, blocking all users from any 1 country seems a little bit overkill; however, try reading up on the RewriteCond directive.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜