Apache - httpd.conf redirect with X-Forward-For - Not working?

16,161

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
Share:
16,161

Related videos on Youtube

waxical
Author by

waxical

Updated on September 18, 2022

Comments

  • waxical
    waxical over 1 year

    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 [email protected]
        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?

  • waxical
    waxical over 12 years
    Just added 'i' after } - but yes! - RewriteCond %{HTTP:X-Forwarded-For}i !^xxx\.xxx\.xxx\.xxx
  • hachi
    hachi over 4 years
    Why would you need "i" flag? Seem to work fine without it.