Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to secure a directory by IP address. I need to access the directory from my ip address (through the browser) and no one else. But I also need to access it via cron (cli). I also have scripts in there that are used by all web visitors via ajax…

I did have a htaccess rule on the directory like so:

order deny,allow
deny from all
allow from
allow from 192.168.0.
allow from 123.456.789.123

That works almost perfectly apart from the ajax calls receive a 403.

Is there a way I can secure the directory but also have the access that I and my web users need?


share|improve this question

Just use:

allow from 192.168.0 123.456.789.123
share|improve this answer
Thanks but that doesn't work. It seems to allow everything! – sulman Jan 30 '12 at 12:00

This has nothing to do with several levels. You are just banning some IPs and allowing others. You need to include all allowed IPs in your config to get it working. This also assumes you know all the possible users' IPs.

If you want to provide more security, you can protect some pages/folders by requiring authentication.

For better security, you can use https if needed. This all depends on the sensitivity of your data and whether you are using a trusted or untrusted network.

share|improve this answer
Thanks but HTTPS isn’t what I’m looking for. I not concerned with encrypting the data just stopping some from accessing it and other allowing access. The problem is that if I use authentication on that directory how do I access the files when doing ajax calls and via cron? – sulman Jan 30 '12 at 12:04
I don't know much about ajax, but you need to include the Authorization header in the HTTP request to be able to access a page protected by username/password. – Khaled Jan 30 '12 at 12:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.