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]
</VirtualHost>

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

Is this wrong?

link|improve this question

36% accept rate
feedback

1 Answer

up vote 2 down vote accepted

On the top of my head: shouldn't this

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

be

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

or just

RewriteCond %{HTTP_FORWARDED} !^xxx\.xxx\.xxx\.xxx
link|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
feedback

Your Answer

 
or
required, but never shown

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