Monday, June 4, 2012

.htaccess apache env var not working

i want to setup in my .htaccess apache file the env var for mobile

i have:

SetEnvIf User-Agent "iPhone" devicetype
SetEnvIf User-Agent "Android" devicetype
RewriteRule ^ - [E=DEVICE:%{devicetype}]

but my $_SERVER['DEVICE'] is always empty. why?

Source: Tips4all

1 comment:

  1. You rule will set the $_SERVER['devicetype']

    [devicetype] => 1

    you don't need: RewriteRule ^ - [E=DEVICE:%{devicetype}]

    If you prefer, you can use this:

    RewriteCond %{HTTP_USER_AGENT} "iphone|android" [NC] # i put 2 as example
    RewriteRule ^ - [E=DEVICE:mobile]

    This will set $_SERVER['DEVICE'] to mobile