Simple Slash Reinstall URL

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

The point is, I want the rule to be applied only when the user navigates to the application. I don't want a trailing slash to be added to each filename.

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

+3


source to share


1 answer


The rule you are looking for can be as simple as:

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

      



The pattern url="^app$"

only matches the URL http://www.yourwebsite.com/app

and nothing else.
If you need to restrict 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>

      

+3


source







All Articles