Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Canonical Links Best Practice #1238

Open
markhildreth opened this issue May 29, 2020 · 3 comments
Open

Canonical Links Best Practice #1238

markhildreth opened this issue May 29, 2020 · 3 comments

Comments

@markhildreth
Copy link

markhildreth commented May 29, 2020

Is there a recommended practice for ensuring canonical URLs for a book? For example, the current rust book can be found at these URLs:

  • https://doc.rust-lang.org/book/
  • https://doc.rust-lang.org/book
    • which 302s to /doc/stable/book/ and then /stable/book/.
  • https://doc.rust-lang.org/book/index.html
  • https://doc.rust-lang.org/book/title-page.html (although this one is slightly different, in that the title page section in the ToC is styled as "active").

However, I don't notice a <link rel="canonical" href="https://doc.rust-lang.org/book/"> on any of the resulting documents. Should mdbook offer any recommendations in this regard, and/or a configuration option to allow for a canonical link on pages?

@ehuss
Copy link
Contributor

ehuss commented May 29, 2020

I think it would probably use useful to have a canonical link. Would probably need to add a site-url to the config to specify the canonical URL. Would then need to feed that into the template (perhaps a computed value of site-url joined with the current page's canonical name).

(Note, also briefly discussed adding site-url at #1221 (comment))

@markhildreth
Copy link
Author

markhildreth commented May 30, 2020

@ehuss Thanks for the quick response. Based on your response and some more digging, I see a few ways forward:

1.) Expose the rendered path (e.g., /index.html for the root/README.md) to the template. This is technically all we need: then the user could just create the full URL in their template with the rendered path. Something like....

<link rel="canonical" href="https://example.com{{ rendered_path }}" />

A bit hackish (especially with the "who is supposed to add the slash" confusion), but it works.

2.) In addition to the above, expose a canonical-url option (e.g., "https://example.com"). If this option is specified, then all pages will have the canonical link placed in their header by default, created by adding the rendered path onto the given canonical URL.

You mention a site-url, although I'm not sure that's what we want. For example, you may want to have a latest.example.com and an example.com. These might have different site-url values, but for SEO reasons might want to have the same canonical URL.

@pinage404
Copy link

Hello,

I changed the domain name of a website generated by mdBook

Now, Google doesn't want to index the new URL because it is detected as duplicate content

Duplicate without user-selected canonical
These pages aren't indexed or served on Google

Is there currently a solution ? (Even if it's a bit hacky)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants