Block IPs

Website URL

Would make problems worse lol

Error Message

:no_mouth:

Other Information

Hi guys, how to block all IP addresses from accessing my site except one (mine) with .htaccess file?

1 Like

hey there, try this.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REMOTE_ADDR} !=yourrip
    RewriteRule ^ - [F,L]
</IfModule>

8 Likes

This approach is quite tedious
because your IP changes (it’s dynamic) usually every 24 hours
and you have to edit the .htaccess file every time.

So you would be better off using Protected Directories (see CA) on the root instead…In which you will choose a user/password which needs to be entered before your website can be accessed (more precisely disk space) and then you can always tell your browser to remember your access data and not have to enter them again.

8 Likes

A simpler .htaccess directive is just to use this line:

Require ip 999.999.999.999

If you need to allow more than one IP, you can just add them at the end of this line, like:

Require ip 888.888.888.888 999.999.999.999

With the side notes that:

  • Password protection might be more practical, because it doesn’t block you if your IP address changes, or if you use a different network.
  • Requests that are blocked are still counted towards your hits usage (as well as CPU and EP usage, but that’s negligible for requests that are not handled by PHP).
8 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.