Setting Environment Variables Dynamically


SetEnvIf HTTP_USER_AGENT MSIE iexplorer SetEnvIf HTTP_USER_AGENT MSIE iexplorer=foo SetEnvIf HTTP_USER_AGENT MSIE !javascript


The SetEnvIf directive enables you to set environment variables based on request information, such as the username, the file being requested, or a specific HTTP header value.

This directive takes a request parameter, a regular expression, and a set of variables that will be modified if the parameter matches the expression. This example matches Microsoft Internet Explorer browsers and shows how you can just set a variable, assign it an arbitrary value foo, or even assign it a negated expression.

Later, you can check the existence and value of this variable to perform a variety of actions such as logging a specific request or serving different content based on the type of browser. For example, you could provide simplified HTML pages for text browsers such as Lynx, or for PDA and cell phone browsers.

In fact, checking for the client user agent is so common that mod_setenvif provides the BrowserMatch directive, allowing you to simply write

BrowserMatch MSIE iexplorer=1


Note

Both SetEnvIf and BrowserMatch have noncase sensitive versions, SetEnvIfNoCase and BrowserMatchNoCase, that can be used to simplify the regular expressions in certain situations.





Apache(c) Phrase Book(c) Essential Code and Commands
Apache Phrasebook
ISBN: 0672328364
EAN: 2147483647
Year: 2006
Pages: 254

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net