regex - Apache 根据用户代理提供不同的文件
问题描述
我的问题当用户从手机、台式机或平板电脑访问我的网站时,我想提供不同的 index.html 文件。我正在使用 Apache 并检查我是否可以基于用户代理来完成它。我编写了代码,但在某些情况下应用了错误的条件(例如,将显示带有 Mobile 的 Android 用户标题桌面版本)。Also in case of desktop everything works fine but when mobile or tablet is selected, I'll receive 404. Also I'm sure js/html code works in all cases I did test it locally.
我的问题是我用于条件的正则表达式是否正确?第一,第二,第三不起作用。你也知道为什么我在尝试访问手机或平板电脑时会收到 404 吗?
我的代码 httpd.conf
<IfModule dir_module>
<If "%{HTTP_USER_AGENT} in { 'iPhone', 'Android' } and %{HTTP_USER_AGENT} =~ /Mobile/">
DirectoryIndex mobile/index.html
</If>
<ElseIf "%{HTTP_USER_AGENT} in { 'BlackBerry', 'Opera Mini', 'Windows Phone' }">
DirectoryIndex mobile/index.html
</ElseIf>
<ElseIf "%{HTTP_USER_AGENT} in { 'Tablet', 'Android' } and !%{HTTP_USER_AGENT} =~ /Mobile/">
DirectoryIndex tablet/index.html
</ElseIf>
<ElseIf "%{HTTP_USER_AGENT} =~ /iPad/">
DirectoryIndex tablet/index.html
</ElseIf>
<Else>
DirectoryIndex desktop/index.html
</Else>
</IfModule>
文件结构
htdocs --- desktop
- index.html
- desktop.bundle.js
--- mobile
- index.html
- mobile.bundle.js
--- tablet
- index.html
- tablet.bundle.js
解决方案
推荐阅读
- sorting - Primefaces 数据表 - 排序不起作用
- javascript - 如何将变量从 webform 传递到 javascript 数据值
- spring - Spring Data DynamoDb 与 Spring Boot 集成(java.lang.AbstractMethodError:createPersistentProperty)
- c++ - c++ 常微分方程系统
- php - 使用 Laravel Eloquent 从模态更新数据库中的一行
- javascript - 将数据从服务注入到组件
- dynamics-crm - 缺少 FetchXML 属性
- java - 当我从邮递员那里打来时,在 HttpServletRequest 对象中获取 null
- maven - 指定 maven 安装插件版本
- angular - 如何根据路线添加课程 | 角 6