您的位置:首页 > 运维架构 > Apache

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

2015-06-01 17:12 519 查看
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]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: