Question

I'm trying to prevent duplicate content SEO issues with a new page. It's the default page of a new directory, so by default will be served on either http://site.com/Directory or http://site.com/Directory/Default.aspx.

I like the simple, clean URL of http://site.com/Directory and want to make sure that http://site.com/Directory/Default.aspx does a 301 redirect to the clean URL so there are no duplicate content issues.

I thought this would be a simple fix:

if (Request.Path == "/Directory/Default.aspx")
   RedirectPermanent("/Directory");

but I was surprised to find that Request.Path shows /Directory/Default.aspx even when the browser is pointed to "/Directory", thus the above code would produce an infinite loop.

It seems simple, but I can't find a way to distinguish which page is in the URL. Request.RawURL is no help.

Canonical URLS are a common requirement, so there should be a simple way around this. Anybody have any ideas?

Était-ce utile?

La solution

Just use the canonical <link> tag. It tells Google which page is the "main" page and doesn't require a lot of programming or redirecting.

<link rel="canonical" href="/Directory" />
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top