Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does creating a canonical URL based on the current URL do any good?

I have an MVC3 app written in C# that I'd like to generate rel=canonical tags for. In searching SO for ways to achieve this automatically, I came across this post.

I implemented it in my dev environment and it works as intended and generates tags such as

<link href="http://localhost/" rel="canonical" />.

My question is, what good does this do? Shouldn't the canonical URL point to explicitly where I want it to (i.e. my production site), rather than whatever the URL happens to be?

The reason I bring this up is because my hosting provider (who shall remain nameless for now) also generates another URL that points to my site (same IP address just a different hostname, I have no idea why, they claim it's for reverse DNS purposes -- this is another subject). However, I've started seeing my page show up in Google search results under this mirrored URL. Not good for SEO, since it's "duplicate content". Now, I've fixed it by simply configuring my IIS site to respond only to requests to my site's domain, however, it seemed a good time to look at what type of a solution canonical URLs could have provided here.

Using the solution in the post above, the rel=canonical link tag would have output a canonical URL containing the MIRRORED URL if someone were to go to the mirrored site, which is not at all what I would want. It should ALWAYS be <link rel="canonical" href="http://www.productionsite.com" />, regardless of the URL in the address bar, right? I mean, isn't that the point of canonical URLs or am I missing something?

Assuming I'm correct, is there an accepted, generic way to generate canonical URLs for an MVC3 app? I can obviously define them individually for every page, or I can simply replace the rawUrl.Host parameter in the solution I linked with a hard-coded domain name, I'm just wondering why I see so many examples of people generating canonical URLs this way when it doesn't seem to fit the purpose (at least in my example). What problem are they trying to solve by just inserting the current URL into a rel=canonical link element?

like image 725
Scott Avatar asked Apr 07 '12 16:04

Scott


People also ask

Why is it a good idea to use canonical URLs?

Canonical URLs help search engines consolidate the information they have for the individual URLs (such as links to them) into a single, authoritative URL. Also, if you syndicate your content for publication on other domains, canonical URLs help to consolidate page ranking to your preferred URL.

What is canonical URL and why is it important?

That means the canonical URL element informs Google and other search engines to crawl a website, and what URL to index that specific page's content under. This is important because URLs can have variations, based on a variety of factors, but be serving up the same or similar content.

Why canonical tag is important?

The canonical tag helps Google and other search engines understand which pages have original content and which pages are duplicates. This establishes the proper authority and ranking of the original content, without penalizing it for having a duplicate page elsewhere.

Is canonical good for SEO?

On a high level, canonicalization is good for SEO because it helps Google make sense of duplicate content and minimizes the risk that they pick the wrong URL as the canonical version.


2 Answers

Great question, and you're bang on regarding the mirrored site still getting marked as canonical. In fact, you've got to fix a couple problems before it hammers your "link juice" any harder.

I suspect the main reason is because MVC, by design, is a URL rewriting/routing system. So depending on the massage that occurs to the originally requested URL, people are trying to set the canonical link to the "settled on" final URL format, post rewriting. That said, I think you've dialed in on an oversight most people are having - which is "What about URLs that reached the page, that were NOT anticipated and REWRITTEN to become the valid, canonical path to the URL?" The answer here, is to rewrite these "bad requests" as you discover them. For example: If you rewrote your ISP's mirrored domain requests, then by the time it reaches the loaded page, it's NOW a valid url; This is because it was "fixed" by your rewrite rules. Make sense? So you'll need to update your MVC routes to handle the bad route created by your ISP. NOTE: You MUST make sure you don't use the originally requested URL, but the final, rewritten one, when building the canonical link value.

Continue on for my WWW vs. non-WWW tip, as well as a concern about something you mentioned regarding not processing the invalid urls.

People also do this because your site already "mirrors" another domain that people always forget about. The "WWW" subdomain.

Believe it or not, although debated, many are stating that having www.yourdomain.com/mypage.htm and yourdomain.com/mypage.htm is actually hurting your page ranking due to "duplicated" content. I suspect this is why people are showing the "same domain" there, because it's actually the domain stripped of the "WWW". (I use a rewrite rule to make the www vs no-www consistent.)

Also, be careful regarding "configuring my IIS site to respond only to requests to my site's domain" because if Google still sees links there and considers them a part of your site, it might actually just penalize you for having pages that fail to load (i.e. 404s) I recommend having a rewrite rule that sends them to your "real" domain OR at least have the canonical link be setup to only use your "real" domain with the WWW consistently there, or not there. (It is argued which is better, I don't think it matters as long as you are consistent.)

like image 137
Dylan - INNO Software Avatar answered Sep 22 '22 05:09

Dylan - INNO Software


What problem are they trying to solve by just inserting the current URL into a rel=canonical link element?

None! They just make things even worse! They have just been mislead

There are misleading answers for this matter, here also on stack overflow which have been accepted and up-voted!!

The whole concept is to produce a unique link ID for each page with different content in a canonical tag.

So a good way to produce unique links for your canonical tags is based on.

Controller Name , Action Name and Language.Those 3 variations will provide different content.

Domain , Protocol and Letter casing don't!

See the question and my answer here for a better understanding.

MVC Generating rel="canonical" automatically

like image 25
Anestis Kivranoglou Avatar answered Sep 24 '22 05:09

Anestis Kivranoglou