Search code examples
iisurl-rewritinghttp-redirectumbraco7

How to set a condition in IIS UrlRewrite to check if the URL is valid


I have an issue with setting an condition for my IIS URLRewrite to set it so when the entered url is not valid then it takes you to a set url. for instance you type url: example.local/current_work that would be a valid url so it shows the page however for url : example.local/this_doesnt_exist it will redirect you back to the example.local/current_work etc...

Hope I am clear on this one.

<rewrite>
 <rules>
  <rule name="Test" stopProcessing="true">
   <match url="^scottishtrunkroadsse.amey.local/([_0-9a-z-]+)" negate="false"/>
     <conditions>
         <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
         <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
     </conditions>
   <action type="Redirect" url="current-works/" />
  </rule>
 </rules>
<rewrite>

Thank you for any help.

I am using an Umbraco website but I don't think that change anything as the IIS url should be working in the same way.

Thank you in advance.


Solution

  • This rule will redirect example.local/this_doesnt_exist to example.local/current_work:

    <rule name="Test" stopProcessing="true">
       <match url="^this_doesnt_exist$" />
       <action type="Redirect" url="/current_work" />
    </rule>