2012-02-12 27 views
6

我想安裝在我的.htaccess文件的Apache移動的.htaccess的Apache的環境變量不工作

中的環境變量,我有:

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

但我的$ _ SERVER [「DEVICE」]總是空。爲什麼?

回答

8

您的規則將設置$_SERVER['devicetype']

[devicetype] => 1

你並不需要:RewriteRule^- [E=DEVICE:%{devicetype}]

如果你願意,你可以使用這個:

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

這將設置$ _SERVER ['DEVICE']至mobile

+0

O.M.G.我感到愚蠢的感謝 – 2012-02-12 22:04:24

+0

嘿,沒問題 – 2012-02-12 22:05:00