Howie
Howie

Reputation: 2778

Simple trailing slash URL rewrite

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/.

Upvotes: 3

Views: 5036

Answers (1)

cheesemacfly
cheesemacfly

Reputation: 11762

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>

Upvotes: 3

Related Questions