从移动浏览器打开时,URL重定向/重写 [英] URL Redirect/Rewrite when opened from Mobile Browser
问题描述
我们正在开发两个网站,其中一个是webapplication,另一个是移动应用程序。
We are working on two website, where one is webapplication and another is mobile application.
所以我的要求是创建一个重定向网址,以便从webapplication重定向到移动设备移动用户的应用程序,但文件夹或结构是不同的。
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>
它将与exactely 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屋!