user8395968
user8395968

Reputation:

How to block ips with .htacces

I need to block certain ip addresses on my website preferably with .htaccess methods. Can someone help me? I request that i be given some sort of URL or code examples here thank you!

Upvotes: 0

Views: 35

Answers (2)

Rounin
Rounin

Reputation: 29521

I need to block certain ip addresses on my website preferably with .htaccess methods.

You can indicate which addresses you wish to block using RewriteCond %{HTTP_REFERER}.

Working Example:

# BLOCK VISITORS REFERRED FROM GOOGLE.COM

RewriteCond %{HTTP_REFERER} ^https?://([a-z0-9-]+\.)?google\.com [NC]
RewriteRule .* - [F]

The example above uses a regular expression, so it will block:

  • https:// or http://
  • followed by any subdomain (or none)
  • followed by google.com
  • followed by anything (or nothing)

The [F] flag means Forbidden. The server will return a 403 Forbidden Error.

Upvotes: 1

sheplu
sheplu

Reputation: 2975

deny from ip_address should work

Edit: add link http://www.htaccess-guide.com/deny-visitors-by-ip-address/

Upvotes: 1

Related Questions