Fix subdirectory canonical URLs dropped by SEO base_url handling - #230
Draft
cursor[bot] wants to merge 2 commits into
Draft
Fix subdirectory canonical URLs dropped by SEO base_url handling#230cursor[bot] wants to merge 2 commits into
cursor[bot] wants to merge 2 commits into
Conversation
PR #229 emitted site-wide canonical/og:url tags via canonical_url_for_output(), but root-relative prefixes such as the documented --base-url /tor-metrics were dropped, so every page canonicalized to /country/US/ instead of /tor-metrics/country/US/. Preserve the path prefix and reject bare "/" which would otherwise produce scheme-relative vanity links. Co-authored-by: 1aeo <1aeo@users.noreply.github.com>
A bare --base-url / is truthy for vanity URL generation and produces
scheme-relative //{domain}/ links. Fail fast in CLI validation so
operators must use a real subdirectory prefix or an absolute http(s)
URL.
Co-authored-by: 1aeo <1aeo@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--base-urlpath prefixes (e.g./tor-metrics) in site-wide canonical and Open Graph URLs--base-url /, which otherwise produces scheme-relative//{domain}/vanity linksBug and impact
PR #229 added site-wide canonical/
og:urltags viacanonical_url_for_output(). For the documented subdirectory preview form--base-url /tor-metrics, the prefix was discarded, so pages emitted canonicals like/country/US/instead of/tor-metrics/country/US/.Trigger: generate with
--base-url /tor-metricsas shown indocs/user-guide/deployment.md.Impact: every generated page gets wrong absolute-path canonical and Open Graph URLs, breaking SEO/social identity for subdirectory deployments. Pre-#229 contact vanity canonicals included the prefix; this is a regression.
Root cause
public_base_url()only accepts absolutehttp(s)origins. When it returnedNonefor root-relative bases,canonical_url_for_output()fell back to the bare site route and ignored the configured path prefix.Fix and validation
root_relative_base_prefix()and use it when building canonicals--base-url /in CLI validation and canonical helperspython3 -m pytest tests/unit/test_seo.py tests/unit/test_search_discovery.py -q→ 22 passed/rejected,/tor-metricsaccepted