我有一套testing各种移动设备的RewriteCond规则,然后在useragent匹配iPhone或Android设备时设置“env = device:.iphone”或“env = device:.smartphone”等环境variables。
我正尝试通过错误页面将用户redirect到每个设备的定制样式的404/500服务器错误页面。
理想情况下,我希望能够testing一个variables,然后写入一个自定义的ErrorDocumentstring。 但是,在这种情况下,apache似乎不起作用。
任何想法如何构build如果/其他testing在环境variables的apache conf文件?
从Apache 2.3版本开始,你可以使用IF构造。 这在Apache的文档中有描述 。
ErrorDocument不允许有条件的东西,但它确实做了一个内部的redirect。
你应该可以用mod_rewrite来完成这个工作:
ErrorDocument 404 /normal_404.html RewriteEngine on RewriteCond %{ENV:device:.iphone} 1 RewriteRule ^/normal_404.html$ /iphone_404.html [L]