If you create a new asp.net mvc website the default routing in Global.asax.cs
is as follows:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
}
This means that the following urls all resolve to the same page.
- mysite.com
- mysite.com/home
- mysite.com/home/index
If anyone hits mysite.com/home
or 开发者_如何学JAVAmysite.com/home/index
I want the url to be mysite.com
. This is the best url for it. Also it would mean that Google and other search engines don'think I have duplicate content.
How would I do this?
you could try two options:
- Check out here for how to create URL rewrite rule.
You can also call for
context.Response.RedirectPermanently("mysite.com"); // you can do this in custom httphandler
If anyone hits mysite.com/home or mysite.com/home/index
not sure if this solves your Google search engine content duplicate.
This answer isn't specific to ASP.NET MVC, as you can use this on any page to confirm the correct canonical page for the content... for example, if you visit
www.stevefenton.co.uk/Content/Home/
You will see the following element in the head of the document...
<link rel="canonical" href="http://www.stevefenton.co.uk/">
This confirms to web crawlers that the master address for the page is in fact the root page.
To make this specific to your ASP.NET MVC page, your best bet is to ensure you always link to the correct variant of your address, so all links point to the correct place. Web crawlers follow your links (as do your users) so if your links are correct, they will index the content for those links.
精彩评论