Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess block all but my ip

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 ?

like image 904
ttmt Avatar asked Dec 18 '12 14:12

ttmt


People also ask

How do I restrict IP address in htaccess?

Step 1: Generate the Country's IP Addresses Select the countries you want to block or allow. On the Select Format section, choose Apache . htaccess Deny or Apache . htaccess Allow.

What does htaccess Deny from all do?

Copied! If you're currently testing your site or setting it to maintenance mode, you might want to restrict visitors from accessing it. You can do so by adding the deny from all command to .

How do I restrict websites accessing IP addresses?

Go to Hosting → Manage → IP Manager: There, you will be able to find 2 options: add IPs to allow and block access to your website: Just add an IP you wish to create rules for, leave a note (optional) and click on Add.


1 Answers

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.

like image 200
MickeyRoush Avatar answered Sep 23 '22 15:09

MickeyRoush