从移动浏览器打开时 URL 重定向/重写 [英] URL Redirect/Rewrite when opened from Mobile Browser

查看:36
本文介绍了从移动浏览器打开时 URL 重定向/重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发两个网站,一个是网络应用程序,另一个是移动应用程序.

We are working on two website, where one is webapplication and another is mobile application.

所以我的要求是为移动用户创建一个重定向 url 以从 web 应用程序重定向到移动应用程序,但文件夹或结构不同.

So my requirement is to create a redirection url to redirect from webapplication to mobile application for mobile users but the folder or structure is different.

对于 Web 应用程序,它是http://testrequest.com/home/Account/对于移动设备,它应该是 http://m.testresponce.com/mforyourhome/Account.aspx

For Web Application it's http://testrequest.com/home/Account/ and for mobile it should be http://m.testresponce.com/mforyourhome/Account.aspx

请有人帮助我使用 URL 重写.

Please can someone help me on using the URL Rewrite.

已- 在 IIS7 上工作

Edited:- Working on IIS7

推荐答案

您可以使用 {HTTP_USER_AGENT} 条件来执行此操作.
应用于您的情况,如下所示:

You can use the {HTTP_USER_AGENT} condition to do this.
Applied to your case, it would be as follow:

<rule name="Mobile Redirect" stopProcessing="true">
    <match url="^home/Account/$" ignoreCase="true" />
    <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
        <add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
        <add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
        <add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
    </conditions>
    <action type="Redirect" url="http://m.testresponce.com/mforyourhome/Account.aspx" appendQueryString="false" />
</rule>

它将完全匹配 home/Account/,如果用户从移动设备浏览,他/她将被重定向到 http://m.testresponce.com/mforyourhome/Account.aspx

It will match exactely home/Account/ and if the user is browsing from a mobile device, he/she will be redirected to http://m.testresponce.com/mforyourhome/Account.aspx

重要

仅在 http://testrequest.com/ 上应用此规则(或至少避免陷入无限重定向).
用户代理永远不会 100% 可靠(因为它们可以更改)

Apply this rule on http://testrequest.com/ only (or at least avoid being stuck in an infinite redirect).
User agent are never 100% reliable (since they can be changed)

来源:http://forums.iis.net/t/1169853.aspx

这篇关于从移动浏览器打开时 URL 重定向/重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆