Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect rule in web.config

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>
like image 282
user1970778 Avatar asked Nov 27 '14 21:11

user1970778


People also ask

How do I create a redirect rule in IIS?

Creating a redirect rule To do this, open the URL Rewrite feature view UI in IIS Manager. Click Add Rule(s)…, and then select the Blank Rule template again. Within the Edit Rule page, enter the following: Name: Redirect from blog (This is a unique name for the rule.)


1 Answers

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.

like image 119
Brandon Spilove Avatar answered Sep 24 '22 19:09

Brandon Spilove