3

I've never done URL rewriting (redirecting). I have a website http://sub.sub.domain.ext/app/. "app" signifies an "Application", not a virtual directory. When a user navigates to http://sub.sub.domain.ext/app (no slash) I need the IIS 7 to redirect him to the URL with the trailing slash.

The thing is that I want the rule to be applied only when the user navigates to application. I don't want the trailing slash to be appended to every filename.

I have tried modifying the predefined rule in IIS7 manager but with no success. I've tried exact matching the whole URL, constraining the conditions, or simply using the original predefined rule. But even when using the original rule, it rewrites all subsequent request files/dirs/URLs, but it does not redirect the user from http://sub.sub.domain.ext/app to http://sub.sub.domain.ext/app/.

Howie
  • 2,760
  • 6
  • 32
  • 60

1 Answers1

3

The rule you are looking might be as simple as:

<rule name="Add trailing slash" stopProcessing="true">
    <match url="^app$" negate="false" />
    <action type="Redirect" url="{R:0}/" />
</rule>

The url="^app$" pattern matches only the url http://www.yourwebsite.com/app and nothing else.
If you need to limit this behavior to the host sub.sub.domain.ext, you can add a condition:

<rule name="test" stopProcessing="true">
    <match url="^app$" negate="false" />
    <action type="Redirect" url="{R:0}/" />
    <conditions>
        <add input="{HTTP_HOST}" pattern="^sub.sub.domain.ext$" />
    </conditions>
</rule>
Owen Blacker
  • 4,117
  • 2
  • 33
  • 70
cheesemacfly
  • 11,622
  • 11
  • 53
  • 72
  • Where would I add this rule? In web.config file in the folder itself? In web.config in the parent folder? Anywhere else? Please add that crucial bit of information for IIS newbies like me. – Jpsy Apr 19 '18 at 07:48
  • Oh, and please add the section hierarchy the rule should be placed in. – Jpsy Apr 19 '18 at 07:54
  • 1
    @Jpsy hey, you can use the GUI if you're unsure about where these should go. Take a look at this answer for a quick guide on how to do so: https://stackoverflow.com/a/14263969/1443490 – cheesemacfly Apr 19 '18 at 19:08