Reputation: 467
Using Apache 2.4's htaccess file, some redirects and headers are configured.
How can I configure it to send a specific header to all but specific IP?
Something like this wrong code:
RewriteCond %{REMOTE_ADDR} ^1.2.3.4$
Header always set BLAH "is blah"
RewriteCond %{REMOTE_ADDR} !^1.2.3.4$
Header always set BLAH "is no so blah!"
Upvotes: 1
Views: 595
Reputation: 45829
You can set an environment variable if the request originates from a specific IP address(es) and set the header conditionally when that variable is or is not set using the env=
argument to the Header
directive.
For example, using mod_setenvif and mod_headers:
SetEnvIf Remote_Addr "^1\.2\.3\.4$" SPECIAL_IP_ADDRESS
Header always set BLAH "is blah" env=SPECIAL_IP_ADDRESS
Header always set BLAH "is NOT blah" env=!SPECIAL_IP_ADDRESS
Works with both Apache 2.2 and 2.4
Upvotes: 0