Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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>
    ServerAdmin webmaster@foo.com
    DocumentRoot /var/www/vhosts/foo/www.bar.com/htdocs/
    ServerName www.bar.com
    ErrorLog /var/www/vhosts/foo/www.bar.com/logs/error.log
    CustomLog /var/www/vhosts/foo/www.bar.com/logs/access.log common
    RewriteEngine On
    RewriteCond %{X-Forwarded-For}i !^xxx\.xxx\.xxx\.xxx
    RewriteRule ^.*$ http://www.bar.com/ [R,L]

Obv xxx.xxx.xxx.xxx being my IP.

Is this wrong?

share|improve this question

1 Answer 1

up vote 2 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.