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 example.com/bananas 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: oldsite.com/bananas should redirect to newsite.com/fruit/bananas but goes to newsite.com/bananas 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).
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:
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?
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.
Setting disableAlternativeTemplates=true will disable both the "parameter way" (alttemplate=templatealias) and "url way" (domain.com/templatealias) methods of using alternative templates.
Had an example of domain.com/templatealias 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
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 example.com/bananas 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: oldsite.com/bananas should redirect to newsite.com/fruit/bananas but goes to newsite.com/bananas 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!
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: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 theSearchForTemplate
line?Pro tip: this will also disable that behavior (available since 7.2.8 I think) -
disableAlternativeTemplates="true"
.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.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?
Many thanks - will try and report back.
Setting disableAlternativeTemplates=true will disable both the "parameter way" (alttemplate=templatealias) and "url way" (domain.com/templatealias) methods of using alternative templates.
Had an example of domain.com/templatealias 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
is working on a reply...