利用apache的rewrite来代替javascript,实现pc和phone的终端判断和跳转
2015-06-01 17:12
519 查看
1.首页的跳转 http://www.xxx.com/index.shtml
1) javascript版本:
2) .htaccess版本
2.详情页的跳转 http://www.xxx.com/html/game/h5/pc/info/xxx.shtml
1) javascript版本
1) javascript版本:
<script> if (navigator.userAgent.match(/Android/i) || navigator.userAgent.indexOf('iPhone') != -1 || navigator.userAgent.indexOf('iPod') != -1 || navigator.userAgent.indexOf('iPad') != -1) { window.location = "./html/game/h5/phone/index/index.shtml"; } </script> <!--#include virtual="./html/game/h5/pc/index/index.shtml"-->
2) .htaccess版本
RewriteCond %{REQUEST_URI} ^\/index\.shtml|\/$ RewriteCond %{HTTP_USER_AGENT} "(baidu.Transcoder|mini|android|blackberry|googlebot-mobile|iemobile|Mobile|ipad|iphone|ipod|opera mobile|palmos|webos|ucweb|Windows Phone|Symbian|hpwOS)" [NC] RewriteRule ^.*$ ./html/game/h5/phone/index/index.shtml [PT] RewriteCond %{REQUEST_URI} ^\/index\.shtml|\/$ RewriteRule ^.*$ ./html/game/h5/pc/index/index.shtml [PT]
2.详情页的跳转 http://www.xxx.com/html/game/h5/pc/info/xxx.shtml
1) javascript版本
<script> var page = document.location.href; //非pc浏览器 //默认访问pc页面,手机上需要根据屏幕尺寸分别跳转到ipad或者iphone页面! if (typeof window.orientation != 'undefined') { page = page.replace(/pc/ig, "phone"); window.location = page; } </script>2).htaccess版本
RewriteCond %{REQUEST_URI} ^\/html\/game\/h5\/pc\/info RewriteCond %{HTTP_USER_AGENT} "(baidu.Transcoder|mini|android|blackberry|googlebot-mobile|iemobile|Mobile|ipad|iphone|ipod|opera mobile|palmos|webos|ucweb|Windows Phone|Symbian|hpwOS)" [NC] RewriteRule ^.*\/(.+)\.shtml$ ./html/game/h5/phone/info/$1.shtml [PT]
相关文章推荐
- Apache Spark源码走读之3 -- Task运行期之函数调用关系分析
- 五种开源协议的比较(BSD,Apache,GPL,LGPL,MIT)
- (9) 如何用Apache POI操作Excel文件-----应用条件样式(ConditionalFormatting)
- Apache配置参数deny和allow的使用实例
- CentOS安装Apache
- ApachePhpMysql64位环境搭建
- (8) 如何用Apache POI操作Excel文件-----POI-3.10.1 的一个黑白颜色颠倒的bug以及解决方案
- apache 对目录进行认证
- Apache VirtualHost配置
- apache 修改端口号无效
- Windows下apache ant安装、环境变量配置教程
- 在Mac下配置php开发环境:Apache+php+MySql
- i春秋:警惕Apache站上的解析缺陷绕过上传漏洞
- apache 配置虚拟主机 url重写功能
- 基于Apache OLTU的OAuth2.0授权解决方案
- apache 无法加载Subversion的mod_dav_svn模块,解决办法
- 源码编译apache 2.4.3 常见问题
- XAMPP在Mac下的apache站点主目录更改
- 转:apache安装后no service install解决办法
- 解决Ubuntu14 apache2虚拟主机目录403错误代码