patel.milanb
patel.milanb

Reputation: 5992

URL Rewrite does not work when URL ending with "/" in asp.net

I have a URL Rewrite in place which works fine BUT when you put "/" in the end it does not work...

how do i work out those urls ... please suggest

<rewriteMap name="Survey2013">
        <add key="/discount" value="/survey/store/" />
        <add key="/discount/" value="/survey/store/" /> // i have to add this URL as well
        <add key="/discounts" value="/survey/store/" />
        <add key="/discounts/" value="/survey/store/" />    
</rewriteMap>

 <rule name="Redirect for Survey2013" enabled="true">
        <match url=".*" />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
            <add input="{Survey2013:{REQUEST_URI}}" pattern="(.+)" />
        </conditions>
        <action type="Redirect" url="{C:1}" appendQueryString="true" />
    </rule>

Upvotes: 1

Views: 141

Answers (1)

cheesemacfly
cheesemacfly

Reputation: 11762

You can change the pattern in your condition to take an optional trailing / with pattern="(.+)/?".

Your rule will become:

<rule name="Redirect for Survey2013" enabled="true">
    <match url=".*" />
    <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{Survey2013:{REQUEST_URI}}" pattern="(.+)/?" />
    </conditions>
    <action type="Redirect" url="{C:1}" appendQueryString="true" />
</rule>

Upvotes: 2

Related Questions