URL Redirect/Rewrite when opened from Mobile Browser

后端 未结 2 1742
刺人心
刺人心 2021-01-14 00:14

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

So my requirement is to create a redirection url to redirect from webap

相关标签:
2条回答
  • 2021-01-14 00:38

    To block redirect when return from your mobile site:

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

    0 讨论(0)
  • 2021-01-14 00:40

    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>
    

    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

    Important

    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)

    Source: http://forums.iis.net/t/1169853.aspx

    0 讨论(0)
提交回复
热议问题