0
votes

I am trying to figure out how to add a rule to my web.config so it detects any link that has anything in the url beyond the .com portion - and then does not process the next input condition which detects if the device is mobile and then redirects to m.mysite.com.

For example here are some example cases I would want it to skip over the mobile redirect:

  • If a incoming link is www.mysite.com/coupon/etc
  • If a incoming link is www.mysite.com?c=1

I do want it to redirect to the mobile site in all cases where its just the base domain of www.mysite.com or mysite.com.

Here is my current web.config rewrite section.

<rewrite>
  <rules>
    <rule name="MobileRedirect" patternSyntax="ECMAScript" stopProcessing="true">
      <match url=".*" ignoreCase="true"/>
      <conditions logicalGrouping="MatchAll">
        <add input="{HTTP_COOKIE}" pattern="persistdesktop=1" ignoreCase="true" negate="true"/>
        <add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos"/>
      </conditions>
      <action type="Redirect" url="http://m.mysite.com" appendQueryString="false" redirectType="Found"/>
    </rule>
  </rules>

So my best guess is that I need to add another condition above the other two. And then do I change the conditions logicalGrouping parameter to MatchAny? Or do I create another rule above this existing rule? Thanks!

1
Can I get any help on this post? stackoverflow.com/questions/33990284/…Josh

1 Answers

1
votes

You haven't set the ignoreCase attribute value to true for HTTP_USER_AGENT. The match URL pattern and the Query string pattern need some changes.

Change the rewrite configuration to:

<rewrite>
    <rules>
        <rule name="MobileRedirect" stopProcessing="true">
            <match url="^$" ignoreCase="false" />
            <conditions logicalGrouping="MatchAll">
                <add input="{HTTP_COOKIE}" pattern="persistdesktop=1" negate="true" />
                <add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera" ignoreCase="true"/>
                <add input="{QUERY_STRING}" pattern="^$"/>
            </conditions>
            <action type="Redirect" url="http://m.mysite.com" redirectType="Found" />
        </rule>
    </rules>
</rewrite>