acg
acg

Reputation: 961

Rewrite IIS Url's Except App Root

I hate Regex's and it hates me, here is the problem:

I am dealing with the infamous Angular routing and legacy browsers (IE9+), I have solved all issues but one, which is that in IE the root url for the app requires a forward slash (and only the root). At the same time I need to remove all forward slashes from other non root requests as demonstrated here in this borrowed snippet:

<rule name="Remove trailing slash" stopProcessing="true">
   <match url="(.*)/$" />
   <conditions>
      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
   </conditions>
   <action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>

This works perfectly, I just do not know how to get a request for exactly this: http://localhost/jumpstart

Rewritten as: http://localhost/jumpstart/ with the trailing slash, while preserving the other rule for non app roots requests.

I thought a match of *\/jumpstart(?!\/) would suffice, but it fails to work.

Any help would be appreciated.

Thanks!

Upvotes: 0

Views: 172

Answers (1)

l&#39;L&#39;l
l&#39;L&#39;l

Reputation: 47219

You should be able to use something such as:

<rule name="Add trailing slash to jumpstart" stopProcessing="true">
  <match url="(.*[^/])$" />
  <conditions>
    <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
    <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
    <add input="{REQUEST_FILENAME}" pattern="(.*?)jumpstart$" negate="true" />
  </conditions>
  <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
</rule>

Upvotes: 1

Related Questions