Copied to clipboard

Flag this post as spam?

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


  • jake williamson 207 posts 873 karma points
    Jul 19, 2021 @ 01:28
    jake williamson
    0

    trailing slash rewrite rule for v8

    hey out there,

    we've a new v8 site going live tomorrow and i'm keen to get a trailing slash rewrite rule set up.

    i remember in v7 this was a little bit of a risky one as it can really mess up the backoffice...

    has anyone got an ultimate redirect for v8 that's rock solid for the trailing forward slash that they could post here so it can forever be the gospel according to seo?!?!

    cheers,

    jake

  • Yakov Lebski 591 posts 2346 karma points
    Jul 19, 2021 @ 02:26
    Yakov Lebski
    0

    not sure what you need it, in umbracoSettings.config

    in section <requestHandler>

    add

    <addTrailingSlash>false</addTrailingSlash>
    
  • jake williamson 207 posts 873 karma points
    Jul 19, 2021 @ 08:33
    jake williamson
    0

    hey yakov,

    thanks for the reply ;)

    i've just checked the docs for that setting as i've never quite understood it:

    https://our.umbraco.com/documentation/reference/config/umbracosettings/#addtrailingslash

    <requestHandler>
        <!-- this will add a trailing slash (/) to urls when in directory url mode -->
        <addTrailingSlash>true</addTrailingSlash>
    </requestHandler>
    

    As mentioned in the comment above, this will add a trailing slash to the url when

    regardless of if i set it to true or false i can still access the page using the url with and without the trailing forward slash meaning both these urls work:

    https://localhost:44377/search

    https://localhost:44377/search/

    the only difference is that in the backoffice, if the setting is set to false the url changes in the info tab:

    enter image description here

    so although the setting changes the url in the backoffice, it doesn't enforce it with a redirect on the front end...

    confusing eh?!

    cheers,

    jake

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Jul 19, 2021 @ 22:37
    Alex Skrypnyk
    0

    Hi Jake

    You can use this rewrite rule:

    <rule name="Add trailing slash" stopProcessing="true">
              <match url="(.*[^/{2,}])$" ignoreCase="true" />
              <conditions>
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/umbraco/" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/install/" negate="true" />
                <add input="{REQUEST_URI}" pattern="^/([0-9]+).aspx" negate="true" />
                <add input="{URL}" pattern="^.*\.(asp|aspx|axd|asmx|css|js|jpg|jpeg|png|gif|mp3|htm)$" negate="true" ignoreCase="true" />
                <add input="{URL}" pattern="/Base" negate="true" />
                <add input="{URL}" pattern="cdv=1" negate="true" />
              </conditions>
              <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
            </rule>
    
  • Yakov Lebski 591 posts 2346 karma points
    Jul 19, 2021 @ 23:06
    Yakov Lebski
    0

    change is not only in backooffice, it's change url provider to generate url with or without / at the end.

    if you want redirect urls with "/" to url without yoou can add this redirrect rule, very important to do it together, owerwise site will generate links links with redirects

      <rule name="Remove trailing slash" stopProcessing="true">
          <match url="(.*)/$" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
          </conditions>
          <action type="Redirect" redirectType="Permanent" url="{R:1}" />
        </rule>
    
  • Tobias 14 posts 86 karma points
    Apr 03, 2024 @ 08:34
    Tobias
    0

    This code ruins Umbraco Preview in backoffice (Version 12).

    Here's a corrected version:

            <rule name="Remove trailing slash, except for Umbraco backoffice" stopProcessing="true">
            <match url="(.*)/$" ignoreCase="true" />
            <conditions logicalGrouping="MatchAll">
                <add input="{REQUEST_URI}" pattern="^/(umbraco/)" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            </conditions>
            <action type="Redirect" redirectType="Permanent" url="{R:1}" appendQueryString="true" />
        </rule>
    
Please Sign in or register to post replies

Write your reply to:

Draft