Trent Miller
Trent Miller

Reputation: 237

.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?

Upvotes: 6

Views: 424

Answers (1)

Book Of Zeus
Book Of Zeus

Reputation: 49877

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

Upvotes: 8

Related Questions