2

I'm trying to use the root IIS 7.5 web.config to redirect certain URLS.

For instance a perfect example of what I am trying to achieve is redirecting to WebMail.

So if someone was to browse to http://www.clientwebsite1.com/webmail they would be redirected to http://www.ownerwebsite.com/webmail.

I have this currently:

<location allowOverride="true">
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="MEWebMail">
          <match url="^webmail/([^/]*)$" />
          <action type="Redirect" url="http://www.ownerwebsite.com/MEWebMail/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</location>

Though so far it seems not to work, any ideas or can I even do this?

Thanks for your help.

Anthony
  • 441
  • 1
  • 5
  • 20
  • Seems to work just fine here. Just only spotted that your rule redirects to `/MEWebMail` but in your text you say you want to redirect to `/webmail`. Oversight or error? – Marco Miltenburg Jun 27 '12 at 21:32
  • 1
    Yes, the rule you provided appears to work for *all* hostnames pointing to your IIS instance. If you want to specify exactly which host and path are redirected see my answer. – Sean Glover Jun 27 '12 at 22:06
  • You say it is working yet for me it isn't :( Does it only work for new sites created after the change? What if there are Rewrite rules in child configs, will these fire before or after the root Rewrite rules? I've restarted the server to make sure that wasn't the issue although I believe changing the config resets the lot anyway. (Sorry, /MEWebMail is the intended target) – Anthony Jun 28 '12 at 08:29

1 Answers1

0

Yes, you can add a rule that does your match and add a condition for the HTTP_HOST URL part. I believe the following rewrite rule should work in your case.

<rewrite>
    <rules>
        <rule name="MEWebMail" stopProcessing="true">
            <match url="^webmail/([^/]*)$" />
            <conditions>
                <add input="{HTTP_HOST}" pattern="^www\.clientwebsite1\.com$" />
            </conditions>
            <action type="Redirect" url="http://www.ownerwebsite.com/MEWebMail/" redirectType="Permanent" />
        </rule>
    </rules>
</rewrite>

For more info consult the following rewrite config learn.iis.com articles.

Accessing URL Parts from a Rewrite Rule

Rule conditions

Sean Glover
  • 1,766
  • 18
  • 31