Copied to clipboard

Flag this post as spam?

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

  • James Taylor 14 posts 124 karma points
    Oct 30, 2015 @ 16:14
    James Taylor

    Prevent direct access to templates

    Is there a way to prevent direct access to a template?

    For example if we have a template called "bananas" then a user can visit which, depending on the page, may generate an error or partial content which would be confusing to the user.

    This is coupled with the fact that we are developing a new umbraco site to replace an old .net site and that our templates are named the same as the sections on the "old" site. Therefore, our redirects don't work.

    eg: should redirect to but goes to due to the "bananas" template.

    I found a thread which mentions removing the line from the 404handlers.config file, but this has had no effect.

    Also, renaming the template (and alias) creates errors (I presume there's multiple places to change the name, but haven't managed to hunt them down).

    Any ideas? - thanks!

  • Mark Bowser 266 posts 852 karma points c-trib
    Oct 30, 2015 @ 18:42
    Mark Bowser

    This is called "alt templating". It comes in handy for creating print friendly versions of pages and things like that.

    I was able to successfully disable it in an umbraco 7.2.8 site by navigating to the /config/404handlers.config file and commenting out the line that instructs umbraco to search for templates that match:

    <?xml version="1.0" encoding="utf-8"?>
      <notFound assembly="umbraco" type="SearchForAlias" />
      <!--<notFound assembly="umbraco" type="SearchForTemplate" />-->
      <notFound assembly="umbraco" type="SearchForProfile" />
      <notFound assembly="SEOChecker" type="Handlers.NotFoundHandlers.Inbound404Handler" />
      <notFound assembly="umbraco" type="handle404" />

    After I made the change, I had to recycle the app pool, so the config would be read in. This is where I found this solution: How to disable alt templates in v6

    It sounds like you might have already tried this. Can you post the changes you made to the /config/404handlers.config file and what version of umbraco you are using? Did you make sure to recycle the app pool after removing the SearchForTemplate line?

  • Sebastiaan Janssen 4926 posts 14706 karma points MVP admin hq
    Oct 30, 2015 @ 18:51
    Sebastiaan Janssen

    Pro tip: this will also disable that behavior (available since 7.2.8 I think) - disableAlternativeTemplates="true".

        internalRedirectPreservesTemplate="false" disableAlternativeTemplates="true" disableFindContentByIdPath="false"

    This is in umbracoSettings.config in the bottom.

    I'm actually not sure why we included an extra setting if removing it from 404handlers.config is enough. I'll ask St├ęphane.

  • Stephen 767 posts 2269 karma points c-trib
    Oct 31, 2015 @ 11:43

    404handlers.config is considered "legacy" as it was abused to deal with situations that are not really 404. The "new" way of doing things is via IContentFinder, and the new setting is used by the IContentFinder. For backward compatibility reason, we still support (as in, sort of simulate) the old "not found handlers", which explain why 404handlers.config still works. But the "right" way to do it is to use the new setting.

    Making sense?

  • James Taylor 14 posts 124 karma points
    Nov 02, 2015 @ 12:09
    James Taylor

    Many thanks - will try and report back.

  • Michael Nielsen 99 posts 619 karma points
    May 28, 2018 @ 12:31
    Michael Nielsen

    Setting disableAlternativeTemplates=true will disable both the "parameter way" (alttemplate=templatealias) and "url way" ( methods of using alternative templates.

    Had an example of had been index by Google, so needed to disable that, but still needed to be able to use alternative templates.

    Commenting out SearchForTemplate in /config/404handlers.config, as suggested by Mark solves that.

    So dear HQ, if you plan on removing the legacy bit, then please split the disableAlternativeTemplates settings into to, i.e. disableAlternativeTemplatesViaUrl and disableAlternativeTemplatesViaParameter

Please Sign in or register to post replies

Write your reply to: