How is a canonical url created based on the current url?

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

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

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

My question is, what good does this do? Should the canonical url explicitly indicate where I want (e.g. my production site), and not any url?

The reason I explain this is because my hosting provider (which is still anonymous) also generates a different URL pointing to my site (the same IP address as another host name, I have no idea I have why they say this for reverse DNS purposes - that's another question). However, I began to see that my page appears in Google search results at this mirror URL. Not suitable for SEO, as it "duplicates content." Now I fixed this by simply configuring my IIS site to only respond to requests in my site’s domain, however, it seemed like the right time to see what type of canonical URLs could provide here.

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

Assuming I'm right, is there a generally accepted way to generate canonical URLs for an MVC3 application? I can obviously define them separately for each page, or I can simply replace the rawUrl.Host parameter in the solution that I linked to the hard-coded domain name, I just wonder why I see so many examples of people generating canonical URLs of this when it doesn’t seem to fit the target (at least in my example). What problem are they trying to solve by simply pasting the current URL into the rel = canonical link element?

+6
source share
3 answers

Great question, and you say that the mirror site is still marked as canonical. In fact, you need to solve a couple of problems before they hit your link juice harder.

I suspect the main reason is that MVC, by design, is a URL rewriting system. Thus, depending on the massage that occurs with the originally requested URL, people try to establish a canonical link to the final URL format after rewriting. However, I think you have gained the oversight that most people have - what is “What about the URLs that reached the page that were not expected, and REWRITTEN became the real canonical path to the URL?” The answer here is to rewrite these “bad queries” when you find them. For example: if you rewrote your domain requests with a mirrored ISP domain, then by the time it reaches the loaded page, this is NOW a valid URL; This is because it has been "fixed" according to your rewriting rules. Make sense? Therefore, you will need to update the MVC routes to handle the bad route created by your ISP. NOTE. YOU SHOULD make sure that you are not using the originally requested URL, but the final one, rewritten when creating the canonical link value.

Keep working for my WWW test, not the WWW tip, as well as the fact that you mentioned that you are not processing invalid URLs.

People also do this because your site is already “mirroring” another domain that people always forget about. Subdomain "WWW".

Believe it or not, although discussed, many claim that having www.yourdomain.com/mypage.htm and yourdomain.com/mypage.htm actually harms your page ranking due to "duplicate" content. I suspect that is why people show "the same domain" because it is actually a domain without the "WWW". (I use the rewrite rule to make www vs no-www consistent.)

Also, be careful about “setting up my IIS site to only respond to my site’s domain requests,” because if Google still sees the links there and considers them part of your site, it may actually just punish you for that pages that do not work for loading (for example, 404 s) I recommend having a rewrite rule that sends them to your "real" domain or at least set a canonical link to use only your "real" domain with WWW , or not. (It is argued that this is better, I do not think it matters if you agree.)

+2
source

Creating a canonical URL based on the current URL does NOT do anything good. You must create a canonical URL based on something static, such as database information. For example, if your URL includes, say, the name of a book. You must pull the title of this book from the database and create a canonical URL from THAT and NOT the URL of the current page. Thus, if part of the URL is missing and the page is still displayed, the canonical URL will always be the same.

0
source

What problem are they trying to solve by simply pasting the current URL into the rel = canonical link element?

Not! They just make things worse! They just misled

There are misleading answers on this question, as well as stack overflows that were accepted and up-voted !

The whole concept is to create a unique link identifier for each page with different content in the canonical tag.

Thus, a good way to create unique links for your canonical tags is based on.

Controller Name, Action Name, and Language . These 3 options will provide different content.

Domain , Protocol and Alphabet Case not!

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

MVC Generate rel = "canonical" automatically

0
source

Source: https://habr.com/ru/post/912660/


All Articles