15

I'm trying to do a quick htaccess to block all but my ip.

I have this

    order deny, allow
    deny from all
    allow from "MY IP"

"MY IP" is my ip

I can't see if from my ip - is this the correct way to do this ?

Zulu
  • 8,765
  • 9
  • 49
  • 56
ttmt
  • 5,822
  • 27
  • 106
  • 158
  • `order deny, allow` is invalid syntax, space is not allowed. Apache will produce an error. It should be `order deny,allow` but I can't fix it since edits with <6 characters are not allowed. – dezlov Oct 07 '15 at 09:33
  • 1
    Possible duplicate of [Deny all, allow only one IP through htaccess](http://stackoverflow.com/questions/4400154/deny-all-allow-only-one-ip-through-htaccess) – IvanRF Sep 02 '16 at 23:26

2 Answers2

23

The most efficient way is to white list yourself using the directive designed for that task.

Order Allow,Deny
Allow from 123.456.789.123

Where 123.456.789.123 is your static IP address.

When using the "Order Allow,Deny" directive the requests must match either Allow or Deny, if neither is met, the request is denied.

http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order

Or you could do it with mod_rewrite like so.

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.123$
RewriteRule .* - [F]

Note that 'RewriteEngine On' will be redundant if you already have placed in your rules above this one. So if that's the case you can discard it here.

MickeyRoush
  • 1,264
  • 10
  • 4
7

You have the correct syntax:

order deny,allow
deny from all
allow from 127.0.0.1

(Note: no quotes around the IP address)

You may want to double check you are using the correct IP Address if you are being denied when you think you should have access.

For example, check on http://www.whatsmyip.org/ - maybe you have something in between you and the server, like a proxy, which is being picked up, rather than your own IP Address.

Fenton
  • 241,084
  • 71
  • 387
  • 401
  • 2
    `order deny, allow` is invalid syntax, space is not allowed. Apache will produce an error. It should be `order deny,allow` but I can't fix it since edits with <6 characters are not allowed. – dezlov Oct 07 '15 at 09:32