Reputation: 1427
Okay so we use some simple IP authentication with htaccess for a folder on our site:
order deny,allow
deny from all
allow from 1.1.1.1
But with the new CDN we are on, the actual users IP address comes through in a different server variable, lets say:
$_SERVER['absolutely_true_ip'];
whereas
$_SERVER['remote_addr'];
is not the users true IP
Is there anyway to tell htaccess where to look for the IP we want to authenticate with?
Upvotes: 2
Views: 404
Reputation: 759
Yes this is possible.
X-FORWARDED-FOR is used by most servers (CDNs, Proxys) to send the originating ip (the users ip). So this should to the job:
SetEnvIf X-FORWARDED-FOR 1.1.1.1 allow
order deny,allow
deny from all
allow from env=allow
If your CDN has a different variable name, just edit the first line.
EDIT:
If you want to allow multiple ip's, just duplicate the first line:
SetEnvIf X-FORWARDED-FOR 1.1.1.1 allow
SetEnvIf X-FORWARDED-FOR 2.2.2.2 allow
SetEnvIf X-FORWARDED-FOR 3.3.3.3 allow
order deny,allow
deny from all
allow from env=allow
Upvotes: 1