Copied to clipboard

Flag this post as spam?

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


  • David Zweben 265 posts 749 karma points
    Dec 12, 2018 @ 16:11
    David Zweben
    0

    URL rewriting for front-end pages only?

    Hi,

    I'm trying to set up my site so that web page URLs without a trailing slash redirect to the same URL with a trailing slash (e.g. "/company" becomes "/company/"). The problem I've run into is that, with standard URL rewriting in web.config, all URLs are affected, including those used by Umbraco and the site's plugins. I've added several paths to a list of exclusions on a standard rewrite rule, but things keep breaking.

    Is there a way we can set up a redirect like this in a way that only affects externally-facing web page URLs?

    Any suggestions would be appreciated!

    -David

  • Marc Goodson 2141 posts 14344 karma points MVP 8x c-trib
    Dec 12, 2018 @ 19:05
    Marc Goodson
    0

    HI David

    I usually go in the opposite direction, removing the ending slash and redirecting /company/ to /company.

    But in the rule you could 'negate' the umbraco folders eg

    <rule name="Add trailing slash" stopProcessing="true">
              <match url="(.*[^/])$" 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="^/umbraco_client" 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)$" negate="true" ignoreCase="true" />
                <add input="{URL}" pattern="/mini-profiler-resources" negate="true" />
              </conditions> 
              <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}/" />
            </rule>
    

    or have a look at this approach which explains setting up a whitelist:

    https://24days.in/umbraco-cms/2014/redirect-rules/

    Also to avoid un-necessary redirects, make sure in UmbracoSettings.config you have 'addTrailingSlash' set to true:

    <addTrailingSlash>true</addTrailingSlash>
    
Please Sign in or register to post replies

Write your reply to:

Draft