Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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'm trying to set up access for a directory using .htaccess rules. Apparently, the remote IP is always localhost due to the way the provider ( ) has set things up.

I've noticed that the correct IP is set in the X-Forwarded-For header.

How can I allow access only to some known hosts based on the X-Forwarded-For header?

share|improve this question
RewriteEngine On
SetEnvIfNoCase X-Forwarded-For .+ forwarded=yes
RewriteCond %{ENV:forwarded} yes
RewriteRule ... my conditions ...

X-Forwarded-For can contain more then one ip address if it was forwarded my multiple servers - if that is the case then you need some script to loop trough this list and processes it.

share|improve this answer

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.