apache与nginx在移动终端访问是的rewrite配置

如题:目前想实现如下效果,根目录下的index.html文件,在使用移动终端访问时,用rewrite重定向到/mobile/index.html。求解rewriterul... 如题:目前想实现如下效果,根目录下的index.html文件,在使用移动终端访问时,用rewrite重定向到/mobile/index.html。求解rewriterule改如何配置,之前试了试,貌似所有目录的index.html都会重定向,只需要让根目录的index.html重定向即可。麻烦各位大神指点一下,apache和nginx都需要。 展开
 我来答
云海技术
2015-10-29 · TA获得超过1599个赞
知道大有可为答主
回答量:2899
采纳率:84%
帮助的人:799万
展开全部
这不需要用到重定向,这只在index.html内加入判断的代码即可。看下如下代码,或者再找找网上的代码例子。方向对了,调试就快了。

<script type="text/javascript">

function browserRedirect() {

var sUserAgent = navigator.userAgent.toLowerCase();

var bIsIpad = sUserAgent.match(/ipad/i) == "ipad";

var bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os";

var bIsMidp = sUserAgent.match(/midp/i) == "midp";

var bIsUc7 = sUserAgent.match(/rv:1.2.3.4/i) == "rv:1.2.3.4";

var bIsUc = sUserAgent.match(/ucweb/i) == "ucweb";

var bIsAndroid = sUserAgent.match(/android/i) == "android";

var bIsCE = sUserAgent.match(/windows ce/i) == "windows ce";

var bIsWM = sUserAgent.match(/windows mobile/i) == "windows mobile";

if (!(bIsIpad || bIsIphoneOs || bIsMidp || bIsUc7 || bIsUc || bIsAndroid || bIsCE || bIsWM) ){

}

else

{

window.location.href="/mobile/";

}

}

browserRedirect();

</script>
追问
不让改页面代码……,只能通过apache和nginx的配置来实现…………
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
kk33ll99
2015-10-30 · 超过11用户采纳过TA的回答
知道答主
回答量:28
采纳率:0%
帮助的人:21.3万
展开全部
apache:
RewriteRule ^/$ /mobile/ [R=301,NC]

nginx:
rewrite ^/$ /mobile/ break;
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式