Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm looking for an IIS solution (not programming) to redirect a website to a mobile version of the website. It looks like it might be possible, but not sure, with IIS Redirect or using IIS URL Rewrite 2.0. If this is the case how would one go about this?

Example: redirects to (if mobile device)

Side Note: We are currently using IIS Redirect to redirect http to https.

share|improve this question

You should be able to use a condition in your IIS rewrite rule.

<rule name="MobileBrowser" stopProcessing="true">
  <match url=".*" />
  <conditions logicalGrouping="MatchAll">
    <add input="{HTTP_COOKIE}" pattern="nomobile" ignoreCase="true" negate="true" />
    <add input="{REQUEST_URI}" pattern="/mobile.*" negate="true" />
    <add input="{FileContains:{HTTP_USER_AGENT}}" pattern=".+" />
  <action type="Rewrite" url="" appendQueryString="false" redirectType="Found" />

I don't have a 2008R2 machine to test, and make sure my syntax is correct but it should be enough to get you in the right direction.

The basics of this rule says:

  • Match any URL
  • As long as the browser does not have the "nomobile" cookie
  • The request URL does not already have /mobile in it
  • The user agent matches the contents of a file.

This rule requires the use of a custom provider so you can store all the various user agents that might be mobile (and there is a long list of them). To setup the custom provider, take a look here.

I added the cookie check as some people still like to look at the full size site, even on their mobile device. This gives you a way to handle that by setting a cookie on their browser, and the rule skips them.

There is a slightly simpler version here that matches on a couple of examples too.

share|improve this answer
Thanks! I'll take a look at that. – thames Mar 23 '11 at 17:05

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.