Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

html - .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 ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...