Tip of the week: The "ultimate" site structure setup
There's a saying in Holland that translates to (literally): "A good beginning is half the work". While that is a bit of an exaggeration, starting with a good structure to your new Umbraco site can be very important.
Last Friday I was skyping with my friend Yannick and he was having a little trouble with redirecting the home node of his site and using my search engine sitemap package. After some back and forth we eventually came to the ultimate setup.
Basically, there will always be two nodes: "Site settings" and "Home". The settings node is there so a few site-specific settings (like the Google Analytics account) can be stored. It also helps preventing editors from being able to create documents of just any type. By default, under the "Content" node you can create nodes of all kinds and generally, you want to very much limit what they can create to prevent the site from becoming a mess.
You can see an example of this structure in the following image:
The "Site" node has the hostname(s) of the site set to it, although it doesn't have to have that. Umbraco will present the first node that it finds in the content tree as the homepage of the site.
I've redirected the "Site" node to the "Home" node so that the correct page will be shown to people entering the site. Later on in the development of your site, I'll be using Umbraco's NiceUrl method to point to pages in my site. Some of those NiceUrl calls go to the "Home" page. This will currently point to "/home".
If you've setup your site to redirect using the umbracoRedirect property, you will have created a 302 redirect from "/" to "/home". This is not what you want for two reasons:
- search engines don't like that there are two pages in the site with the exact same content
- search engines know that a 302 redirect means that it's temporary, so they will keep expecting that the "/" and the "/home" pages are supposed to be different
Additionally, you will be faced with another, more immediate couple of problems in Umbraco:
- the altTemplate mechanism controlled by the 404handlers.config gets confused and only works if you prefix the template name with "/home", which would cause a problem with the search engine sitemap package that I mentioned earlier
- you are suddenly unable to save XSLT files from the built-in editor in Umbraco
This is easily fixed though. On the "Site" node, I've put a property of the Content Picker type with the alias of umbracoInternalRedirectId that will not actually do a redirect, but will render whatever node you pick instead of the current node. Logically, I have picked the "Home" node.
This leaves you with a bit of a problem still, as Umbraco's NiceUrl method still produces links to "/home". To solve this, you can just do a simple urlRewrite and make the "/home" call always do a 301 (permanently moved) redirect to "/". Just the way search engines like it. Be careful: this will cause an infinite loop if you do it while the umbracoRedirect property is still on there, only do this with the umbracoInternalRedirectId property.
The urlRewrite config looks like this (note the "$" at the end of "home" is there to make sure that if you want any nodes under your home page, they won't be rewritten as well):
And there you have it, the "ultimate" site structure for you to start your site with. Google is happy, Umbraco is happy (it will save your XSLT files again), everybody is happy!
That being said, this will probably be my last blog post for this year. Happy holidays and see you next year.