利用apache的rewrite来代替javascript,实现pc和phone的终端判断和跳转

1.首页的跳转 http://www.xxx.com/index.shtml

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]



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值