Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 07, 2019 @ 22:38
    Bo Damgaard Mortensen

    URL rewrite map match optional trailing slash

    Hi all,

    I've got a new site where the URLs from the old site needs to be 301 redirected. For this I've set up a rewrite map and added a rewrite rule for it.

    Thing is, with my current rewrite rule, appending a trailing slash to the old URL doesn't match the value in the rewrite map (because URLs there aren't with a trailing slash)

    Snippet from my rewrite map:

    <rewriteMap name="Redirects">
        <add key="" value="" />
        ... and a whole lot more

    and my (rather simple) rule is as follows:

    <rule name="Redirects from old domain" stopProcessing="true">
        <match url=".*" />
            <add input="{Redirects:{HTTP_HOST}{REQUEST_URI}}" pattern="(.+)" />
        <action type="Redirect" url="https://{C:1}" appendQueryString="false" redirectType="Permanent" />

    Does anyone know if there's any way to make this rule match the URL, but with a trailing slash, like so: Have to admit my regex skills aren't the best ;-)

    Thanks a lot in advance.

    All the best,


  • Bo Damgaard Mortensen 719 posts 1207 karma points
    Jan 21, 2019 @ 12:32
    Bo Damgaard Mortensen

    Anyone ? :-D

  • Steve Morgan 1324 posts 4389 karma points c-trib
    Jan 21, 2019 @ 16:35
    Steve Morgan

    Hi Bo,

    Something like:

        <rule name="Add trailing slash" stopProcessing="true">
          <!-- add slash but not to files -->
          <match url="^([^.]*[^/])$" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <!--<add input="{REQUEST_FILENAME}" pattern="(.*?)\.html$" negate="true" />
        <add input="{REQUEST_FILENAME}" pattern="(.*?)\.aspx$" negate="true" />-->
          <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
Please Sign in or register to post replies

Write your reply to: