Skip to content

Multiple Navigation Paths to a Single Page

Shad Storhaug edited this page Apr 24, 2018 · 2 revisions

A common requirement is when a particular product or article fits into multiple categories, you want to be able to navigate to that page using multiple paths. For example:

Home > Red Things > Red Beans
Home > Beans > Red Beans

But how can you do this if a site map node must be unique? The answer is to use 2 site map nodes to point to a single resource. This can be done by either adding query string information to the end of the URL, or by using a different URL path entirely for the alternate navigation. However it is done, the URLs in each case must be unique. Here are some examples:

Differentiating by query string
http://mysite.com/products/index/red-beans?category=red-things
http://mysite.com/products/index/red-beans?category=beans

Differentiating by path
http://mysite.com/red-things/red-beans
http://mysite.com/beans/red-beans
http://mysite.com/on-sale/red-beans

If you are familiar with routing in .NET, you probably already have an idea how to set up your URLs using a method similar to this. The first method is the simplest - add an extra category parameter to the route and it will automatically be generated that way. The only requirement is that you set up each node on a different physical URL.

But wait! That is bad for SEO! Isn't it?

Yes and no. It is bad if you only put the content on different URLs and do nothing else. However, we have provided the framework to easily take advantage of the canonical tag, which is how you can tell search engines you meant to put the same content on multiple URLs. Here is what the XML configuration would look like for the first example above, but keep in mind that you can also set these settings from any of the other methods of building site map nodes.

<?xml version="1.0" encoding="utf-8" ?> 
<mvcSiteMap xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0"
            xsi:schemaLocation="http://mvcsitemap.codeplex.com/schemas/MvcSiteMap-File-4.0 MvcSiteMapSchema.xsd">

	<mvcSiteMapNode title="Home" controller="Home" action="Index">
		<mvcSiteMapNode title="Red Things" controller="categories" action="Index" id="red-things">
			<mvcSiteMapNode title="Red Beans" controller="products" action="Index" id="red-beans-67" category="red-things" key="red-beans" />
		</mvcSiteMapNode>
		<mvcSiteMapNode title="Beans" controller="categories" action="Index" id="beans">
			<mvcSiteMapNode title="Red Beans" controller="products" action="Index" id="red-beans-67" category="beans" canonicalKey="red-beans" />
		</mvcSiteMapNode>
	</mvcSiteMapNode> 
</mvcSiteMap>

In short, the key property of the "main" node must be specified as a canonicalKey in all of the alternate nodes that reach the same resource. Alternatively, you can specify the relationship using canonicalUrl, which is useful if the original page is not on the current web site or you are using a scheme with URLs instead of routes. canonicalKey and canonicalUrl may not be used simultaneously on the same node.

Then you just need to add the canonical helper to your layout page between the <head> tags using the following syntax:

<head>
    @Html.MvcSiteMap().CanonicalTag()
</head>

The correct canonical tag will then be generated automatically. In addition, the `XmlSiteMapController` (`sitemap.xml` page) will automatically exclude the "extra" URLs so the information that the search engines receive is consistently recommending the canonical (authoritive) URL for the index.

Want to contribute? See our Contributing to MvcSiteMapProvider guide.



Version 3.x Documentation


Unofficial Documentation and Resources

Other places around the web have some documentation that is helpful for getting started and finding answers that are not found here.

Tutorials and Demos

Version 4.x
Version 3.x

Forums and Q & A Sites

Other Blog Posts

Clone this wiki locally