Skip to content

Rewrite hexdocs.pm canonical links to per-package subdomains#119

Merged
ericmj merged 1 commit into
mainfrom
rewrite-hexdocs-links-to-subdomains
May 31, 2026
Merged

Rewrite hexdocs.pm canonical links to per-package subdomains#119
ericmj merged 1 commit into
mainfrom
rewrite-hexdocs-links-to-subdomains

Conversation

@ericmj
Copy link
Copy Markdown
Member

@ericmj ericmj commented May 30, 2026

ExDoc emits a <link rel="canonical"> tag (when the package sets the :canonical option) pointing at the old path-based URL, https://hexdocs.pm/<package>/.... Now that docs are served from per-package subdomains, that canonical points away from where the page actually lives, splitting the SEO signal between the apex path and the subdomain.

This rewrites the canonical tag at ingestion time in Hexdocs.FileRewriter so it points at https://<package>.hexdocs.pm/..., reusing package_to_subdomain/1 for the underscore-to-hyphen mapping and upgrading http to https. The bare apex, apex files such as sitemap.xml, and canonical links that already use a subdomain are left untouched.

Body links and other tags are intentionally not rewritten: a permanent 301 redirect from the old URLs preserves link equity, so the canonical tag is the only place where rewriting changes SEO behavior. Only .html files are processed.

@ericmj ericmj marked this pull request as ready for review May 30, 2026 13:15
@josevalim
Copy link
Copy Markdown
Member

Do we need to rewrite the pages, given we redirect anyway? 🤔

@ericmj
Copy link
Copy Markdown
Member Author

ericmj commented May 31, 2026

Long term the plan was to deprecate the redirects but it's the only way we can get things like the sitemap to work so I guess we will keep them forever?

I think presenting one URL format can help for SEO though and help search engines dedup pages.

@josevalim
Copy link
Copy Markdown
Member

What we really need to fix is the canonical. We have fixed it in the past though, right? So maybe do something targeted to that?

ExDoc emits a <link rel="canonical"> tag (when the package sets the
:canonical option) pointing at the old path-based URL,
https://hexdocs.pm/<package>/... . Now that docs are served from
per-package subdomains, that canonical points away from where the page
actually lives, splitting SEO signal.

Rewrite the canonical tag at ingestion time in the file rewriter so it
points at https://<package>.hexdocs.pm/... , reusing package_to_subdomain
for the underscore-to-hyphen mapping and upgrading http to https. The
bare apex, apex files such as sitemap.xml, and canonical links that
already use a subdomain are left untouched.

Body links and other tags are intentionally not rewritten: a permanent
redirect from the old URLs preserves link equity via 301, so canonical
is the only tag where the rewrite changes SEO behavior.
@ericmj ericmj force-pushed the rewrite-hexdocs-links-to-subdomains branch from 890beb4 to d8209ac Compare May 31, 2026 17:09
@ericmj ericmj changed the title Rewrite old-format hexdocs.pm links to per-package subdomains Rewrite hexdocs.pm canonical links to per-package subdomains May 31, 2026
@ericmj ericmj marked this pull request as draft May 31, 2026 17:09
@ericmj ericmj marked this pull request as ready for review May 31, 2026 18:50
@ericmj
Copy link
Copy Markdown
Member Author

ericmj commented May 31, 2026

Updated to only rewrite canonical links

@ericmj ericmj merged commit 42c30d1 into main May 31, 2026
12 checks passed
@ericmj ericmj deleted the rewrite-hexdocs-links-to-subdomains branch May 31, 2026 19:03
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

Successfully merging this pull request may close these issues.

2 participants