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 want to set some environment only for a specific IP,how to do that in Apache?

share|improve this question

1 Answer 1

See the SetEnvIf directive, which defines environment variables based on attributes of the request, such as Remote_Addr (the IP address of the client making the request)...

SetEnvIf Remote_Addr ^192\.168\.0\. LOCAL_LAN=1

...or Server_Addr (the IP address of the server on which the request was received)...

SetEnvIf Server_Addr ^192\.168\.0\.1$ SITE_PROFILE=PRODUCTION
SetEnvIf Server_Addr ^192\.168\.0\.2$ SITE_PROFILE=DEVELOPMENT

Note that the second argument to SetEnvIf is a regular expression, so be extra mindful if you're tempted to use bare IPs, as a pattern like 192.168.1.1 (while looking a lot cleaner than escaping dots as I do above) will also end up matching 192.168.101.10.

UPDATE:

SetEnvIf can't access QUERY_STRING, but per the docs:-

See the RewriteCond directive of mod_rewrite for extra information on how to match your query string.

So something like...

RewriteCond %{REMOTE_ADDR} ^192\.168\.0\.
RewriteCond %{QUERY_STRING} (^|&)debug=
RewriteRule . - [E=LOCAL_LAN_AND_DEBUG:1]
share|improve this answer
    
How can I do it if there's a debug parameter in the querystring? –  linux Jul 14 '11 at 3:42
    
Per the docs, you would need to use mod_rewrite instead. Example added to answer above. –  Kanji Jul 14 '11 at 4:23
    
What does . - mean in . - [E=LOCAL_LAN_AND_DEBUG:1] ? Also does LOCAL_LAN_AND_DEBUG:1 set both LOCAL_LAN and DEBUG to 1? –  linux Jul 14 '11 at 4:51
    
BTW,isn't querystring also stored in environment variables? –  linux Jul 14 '11 at 7:17
    
I just tried,and the environment variable is NOT set though.. –  linux Jul 14 '11 at 9:24

Your Answer

 
discard

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.