.htaccess apache env var not working

I want to configure in my .htaccess file apache 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?

+6
source share
1 answer

You set the rule $_SERVER['devicetype']

[devicetype] => 1

you do not 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 install $ _SERVER ['DEVICE] on mobile

+8
source

Source: https://habr.com/ru/post/908280/


All Articles