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'm having an a-hole of a problem redirecting traffic. Basically, I'm building a new web server and it's on another version of my domain, so I want to redirect traffic not from this IP.

Problem is Amazon's ELB Load Balancer is in the way, so it replaces REMOTE ip address. The normal method of obtaining. Research found I need to use %{X-Forward-For}i - but it's not working and I don't know if I've got it in the right placement and syntax. I'm running vhosts, so I put in the VirtualHost tags...

<VirtualHost *:80>
    DocumentRoot /var/www/vhosts/foo/
    ErrorLog /var/www/vhosts/foo/
    CustomLog /var/www/vhosts/foo/ common
    RewriteEngine On
    RewriteCond %{X-Forwarded-For}i !^xxx\.xxx\.xxx\.xxx
    RewriteRule ^.*$ [R,L]

Obv being my IP.

Is this wrong?

share|improve this question
up vote 3 down vote accepted

On the top of my head: shouldn't this

RewriteCond %{X-Forwarded-For} !^xxx\.xxx\.xxx\.xxx


RewriteCond %{HTTP:X-Forwarded-For} !^xxx\.xxx\.xxx\.xxx

or just

RewriteCond %{HTTP_FORWARDED} !^xxx\.xxx\.xxx\.xxx
share|improve this answer
Just added 'i' after } - but yes! - RewriteCond %{HTTP:X-Forwarded-For}i !^xxx\.xxx\.xxx\.xxx – waxical Oct 26 '11 at 11:59

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.