Copied to clipboard

Flag this post as spam?

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


  • Benjamin Ravn 35 posts 68 karma points
    Mar 14, 2014 @ 10:04
    Benjamin Ravn
    0

    Add trailing slash - but still respons without

    Hi Umbracians

    I have on my site set umbracoUseDirectoryUrls and addTrailingSlash to true so all paths look like this.

    /test/ /test/sub/

    But if I manually remove the trailing slash, the page is still responding on ex. "/test/sub". This is actually bad for SEO, because search engines could see this as duplicate content.

    /test and /test/sub is treated as files while /test/ and /test/sub/ as directories.

    The solution would be to add a 301 redirect, if the trailing slash is missing.

    But why do Umbraco not work that way by default, when the setting clearly says, there should be a trailing slash?

    Does anyone have a quickfix for this, where taking into account the querystring?

    Best regards Benjamin Ravn

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 14, 2014 @ 10:16
    Jan Skovgaard
    0

    Hi Benjamin

    Don't know if you can perhaps use the 301 tracker package to fix this?

    However I'm not sure why Umbraco does not make sure to add the trailing slash under the hood. Maybe it's something no one has ever thought about.

    Perhaps it's a good idea to file a feature request for having this changed on the issue tracker http://issues.umbraco.org/issues

    If you create an issue please put the link in this thread so others can go and vote it up as well should they come across this post.

    Have a nice friday! :)

    /Jan

  • Dan Lister 416 posts 1974 karma points c-trib
    Mar 14, 2014 @ 11:47
    Dan Lister
    0

    It might be a little long winded but what about adding a Url Rewrite rule to your web.config to force a trailing slash? You'll need to Url Rewrite IIS module installed for this to work.

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <system.webServer>
        <rewrite>
          <rules>
            <rule name="Force Trailing Slash" enabled="true" stopProcessing="true">
              <match url="(.*[^/])$" ignoreCase="true" />
              <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
                <add input="{URL}" pattern="/css" negate="true" />
                <add input="{URL}" pattern="/fonts" negate="true" />
                <add input="{URL}" pattern="/images" negate="true" />
                <add input="{URL}" pattern="/scripts" negate="true" />
                <add input="{URL}" pattern="/umbraco_client" negate="true" />
                <add input="{URL}" pattern="/umbraco" negate="true" />
                <add input="{URL}" pattern=".axd" negate="true" />
                <add input="{URL}" pattern=".ashx" negate="true" />
                <add input="{URL}" pattern=".asmx" negate="true" />
                <add input="{URL}" pattern=".aspx" negate="true" />
                <add input="{URL}" pattern=".js" negate="true" />
                <add input="{URL}" pattern=".css" negate="true" />
                <add input="{URL}" pattern=".png" negate="true" />
                <add input="{URL}" pattern=".jpg" negate="true" />
                <add input="{URL}" pattern=".pdf" negate="true" />
                <add input="{URL}" pattern=".txt" negate="true" />
                <add input="{URL}" pattern=".mov" negate="true" />
                <add input="{URL}" pattern=".avi" negate="true" />
                <add input="{URL}" pattern=".gif" negate="true" />
                <add input="{URL}" pattern=".jpeg" negate="true" />
                <add input="{URL}" pattern=".html" negate="true" />
                <add input="{URL}" pattern=".xml" negate="true" />
                <add input="{URL}" pattern=".rss" negate="true" />
                <add input="{URL}" pattern=".ico" negate="true" />
                <add input="{URL}" pattern=".map" negate="true" />
                <add input="{URL}" pattern=".swf" negate="true" />
                <add input="{URL}" pattern=".gif" negate="true" />
                <add input="{URL}" pattern=".woff" negate="true" />
                <add input="{URL}" pattern=".ttf" negate="true" />
                <add input="{URL}" pattern=".otf" negate="true" />
                <add input="{URL}" pattern=".eot" negate="true" />
                <add input="{URL}" pattern=".less" negate="true" />
                <add input="{URL}" pattern=".air" negate="true" />
              </conditions>
              <action type="Redirect" redirectType="Permanent" url="{R:1}/" />
            </rule>
          </rules>
        </rewrite>
      </system.webServer>
    </configuration>
  • Matthew Kirschner 323 posts 611 karma points
    May 17, 2016 @ 15:27
    Matthew Kirschner
    0

    I think the above could be simplified to the follow for Umbraco 7.4.3 and up:

    <rule name="AddTrailingSlashRule1" stopProcessing="true">
        <match url="(.*[^/])$" />
        <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{URL}" pattern="/umbraco_client" negate="true" />
            <add input="{URL}" pattern="/umbraco" negate="true" />
            <add input="{URL}" pattern="/install" negate="true" />
            <add input="{URL}" pattern=".axd" negate="true" />
        </conditions>
        <action type="Redirect" url="{R:1}/" />
    </rule>
    
  • Peter Duncanson 430 posts 1360 karma points c-trib
    May 16, 2017 @ 16:25
    Peter Duncanson
    4

    I tweaked this a bit after using this in the wild to the following:

                <rule name="AddTrailingSlashRule" stopProcessing="true">
                  <match url="(.*[^/])$" />
                  <conditions>
        <!-- General website stuff -->
                      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                      <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <!-- Umbraco stuff -->
                      <add input="{URL}" pattern="/umbraco_client" negate="true" />
                      <add input="{URL}" pattern="/umbraco" negate="true" />
                      <add input="{URL}" pattern="/install" negate="true" />
        <!-- .net stuff -->
                      <add input="{URL}" pattern=".axd" negate="true" />
                      <add input="{URL}" pattern=".ashx" negate="true" />              
        <!-- our internal stuff -->
                      <add input="{URL}" pattern="/media" negate="true" />
                      <add input="{URL}" pattern="/assets" negate="true" />
                  </conditions>
                  <action type="Redirect" url="{R:1}/" />
    </rule>
    
  • Alan Mac Kenna 147 posts 405 karma points MVP c-trib
    Jul 18, 2017 @ 16:03
    Alan Mac Kenna
    2

    Just an FYI on Pete's last post - as is it seems to cause problems with the DocTypeGridEditor Preview in the backoffice. It ends up injecting front-end template HTML into the DTGE preview. The trailing slash seems to throw the preview rendering off.

    To fix this you can add:

    <add input="{REQUEST_URI}" pattern="dtgePreview=1" negate="true" />
    

    In case people start noticing funny behaviour!

Please Sign in or register to post replies

Write your reply to:

Draft