6
votes

I was looking into this Seemingly simple redirect in IIS using web.config file because I have a similar situation, but the approach mentioned there doesn't seem to be working for me.

I have a help section on a web site, which for now I want it to redirect to another place. The rest of the site should stay the same, which means that only the help section/content should make the user go to another site:

device.domain.com/help

device.domain.com/help/version

Should make the request go to

company.custhelp.com

But for example device.domain.com/api should still work. This is what I tried. If I test the pattern inside of IIS it says that it will work. What am I missing?

<system.webServer>  
  <rewrite>
    <rules>
      <rule name="Help Redirect" stopProcessing="true">            
        <match url="(.*)/help(.*)" ignoreCase="true" />
        <action type="Redirect" url="http://company.custhelp.com/" appendQueryString="false" redirectType="Permanent" />
      </rule>
    </rules>
  </rewrite>
  ...
</system.webServer>
1

1 Answers

4
votes

The match url will try to match on the path after the domain, starting from after the slash. So it should be like so:

<match url="help(.*)" ignoreCase="true" />

The match url that you wrote would match on device.domain.com/temp/help, but not device.domain.com/help.