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
    0

    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="myolddomain.com/page/subpage" value="mynewdomain.com/da/subpage/" />
        ... and a whole lot more
    </rewriteMap>
    

    and my (rather simple) rule is as follows:

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

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

    Thanks a lot in advance.

    All the best,

    Bo

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

    Anyone ? :-D

  • Steve Morgan 1346 posts 4453 karma points c-trib
    Jan 21, 2019 @ 16:35
    Steve Morgan
    0

    Hi Bo,

    Something like:

         <rewrite>
      <rules>
        <rule name="Add trailing slash" stopProcessing="true">
          <!-- add slash but not to files -->
          <match url="^([^.]*[^/])$" />
          <conditions>
            <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" />-->
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
        </rule>
      </rules>
     </rewrite>
    
Please Sign in or register to post replies

Write your reply to:

Draft