0
votes

We have an IIS 8.5 setup where a single website is bound to domain.com and contains a number of IIS applications accessed as domain.com/app1, domain.com/app2 etc.

Each of these applications points to the same physical path, so they all share a web.config. This is a specific CMS configuration.

I have applied the usual URL Rewrite rules (redirect to HTTPS, enforce lowercase, add trailing slash etc.) to the web.config each application shares but have realised these rules are only applied to the URL after the application name. The rules I have are just standard rules added using the URL Rewrite GUI:

<rewrite>
  <rules>
    <rule name="Enforce lowercase" stopProcessing="true">
      <match url="[A-Z]" ignoreCase="false" />
      <action type="Redirect" url="{ToLower:{URL}}" redirectType="Permanent" />
    </rule>
    <rule name="Add trailing slash" stopProcessing="true">
        <match url="(.*[^/])$" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        </conditions>
        <action type="Redirect" url="{R:1}/" redirectType="Permanent" />
    </rule>
    <rule name="Redirect to HTTPS" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" />
    </rule>
  </rules>
</rewrite>

So, for example, http://domain.com/APP1/PATH redirects to https://domain.com/APP1/path/. Also, https://domain.com/app1 doesn't redirect to https://domain.com/app1/.

The HTTPS rule is fine, but can anyone tell me how I can configure the other 2 rules so that they work with the entire URL, bearing in mind that the specific application name (app1, app2 etc) needs to be handled generically.

UPDATE

I've discovered that I can enforce lowercase URLs using a global rule in IIS (at server level) which is sufficient for my needs. But it doesn't seem to be possible to replicate the website-level rule for adding/removing trailing slash.

1

1 Answers

0
votes

You just need to change action URL.

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