-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
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 tag contains duplicated base URL when trailingSlash is false #6315
Comments
Oh... yeah. Thanks for reporting! Very clear repro 👍 |
also weird duplicate |
The title of this issue seems akin to my problem ... Im finding that Google is finding but "Excluding" all my Doc pages - other than the root. I notice when I browse to Doc page there a redirect (301) that adds a / onto the end of the URL. This means the URL (which returns a 200) is in conflict with what is in the sitemap.xml ? Is this an issue - or is there another reason Google is excluding Doc pages ? as an aside - when I access a doc using the the side menu - i see the URL in the address bar doesn't have a trailing / |
@markharrison Did you set the |
It looks like there was a change to the default canonical tag that introduced this behavior: https://github.com/facebook/docusaurus/pull/4109/files#diff-5a9766c1abdd0dbd7f0ebafa788297edbaf531835e8b55c6d542e727e4507affL94-L95 From what I can tell, this only occurs on the root page when using Not sure what the expected behavior is, but it also presenting as a bug for our use case as well. Edit |
I see The problem is that you misunderstand that The If you set Note it's a bad SEO practice to make your site available on both URLs, you'd rather redirect This is something that many hosts will do for you automatically, unfortunately, maybe you have a host that has different behavior and you must configure this explicitly. Note that when using baseUrl, your deployment might look like this: - build/index.html
- build/blog.html It's not possible for Docusaurus to remove the trailing slash of a baseUrl reliably (ie that would work with the most popular hosting platforms) because it means Docusaurus would have to emit HTML files outside of its build folder. - documentation.html
- build/blog.html Also worth mentioning: Docusaurus assumes that it is served from the configured baseUrl (and NOT the baseUrl without trailing slash). This means that if you use relative links like We could eventually fix the canonical URL problem but IMHO it's just hiding a deeper issue that you have. We might as well want to make your site explode when accessed through |
Note:
We have many other places where we read current browser location. Accessing your site through Maybe we want to add a warning when the site homepage is served from the wrong location Or do a redirect to add the trailing slash automatically? (I don't like that much because it remains bad for SEO and we might break the site served from the wrong location in the future without even noticing) Would it be a good solution for your use-case? |
It seems that, if Here's a link to a repo to reproduce the bug: Once the trailing Sorry in advance if this comment in this closed issue is not the the right way to report this. If you prefer, I can create a new issue. |
@guerrero that would help me review this faster if you opened a dedicated issue and where your repro code has a deploy preview showing the problem that I can inspect without checking out your repo Also if you have similar problems in hreflang headers that's worth reporting too |
Have you read the Contributing Guidelines on issues?
Prerequisites
npm run clear
oryarn clear
command.rm -rf node_modules yarn.lock package-lock.json
and re-installing packages.Description
If
baseUrl
is set to value other than'/'
(e.g.'/docusaurus-canonical/'
) andtrailingSlash
is set tofalse
, the canonical tag of the main index page will contain a duplicated base URL. Note that this only applies to the canonical tag set by JavaScript and not the static HTML.I suspect this is caused by the
shouldAddBaseUrl
check inaddBaseUrl()
:docusaurus/packages/docusaurus/src/client/exports/useBaseUrl.ts
Line 37 in a2d2324
Assuming
baseUrl
is'/docusaurus-canonical/'
the URL of the main index page is'/docusaurus-canonical'
, sourl
does not start withbaseUrl
.Steps to reproduce
baseUrl
to a value other than'/'
, e.g.'/docusaurus-canonical/'
trailingSlash
tofalse
trailingSlash=false
)Expected behavior
The canonical tag should contain the correct URL of the page, i.e.
${siteUrl}/docusaurus-canonical
.Actual behavior
The canonical tag contains a duplicated base URL, i.e.
${siteUrl}/docusaurus-canonical/docusaurus-canonical
:Your environment
Reproducible demo
https://github.com/ltm/docusaurus-canonical
Self-service
The text was updated successfully, but these errors were encountered: