Skip to content

Fix subdirectory canonical URLs dropped by SEO base_url handling - #230

Draft
cursor[bot] wants to merge 2 commits into
masterfrom
cursor/critical-bug-investigation-4a93
Draft

Fix subdirectory canonical URLs dropped by SEO base_url handling#230
cursor[bot] wants to merge 2 commits into
masterfrom
cursor/critical-bug-investigation-4a93

Conversation

@cursor

@cursor cursor Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve root-relative --base-url path prefixes (e.g. /tor-metrics) in site-wide canonical and Open Graph URLs
  • Reject bare --base-url /, which otherwise produces scheme-relative //{domain}/ vanity links
  • Add regression coverage for subdirectory canonical routes and slash-only rejection

Bug and impact

PR #229 added site-wide canonical/og:url tags via canonical_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-metrics as shown in docs/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 absolute http(s) origins. When it returned None for root-relative bases, canonical_url_for_output() fell back to the bare site route and ignored the configured path prefix.

Fix and validation

  • Add root_relative_base_prefix() and use it when building canonicals
  • Fail fast on --base-url / in CLI validation and canonical helpers
  • python3 -m pytest tests/unit/test_seo.py tests/unit/test_search_discovery.py -q → 22 passed
  • Manual CLI smoke check: / rejected, /tor-metrics accepted
Open in Web View Automation 

cursoragent and others added 2 commits August 2, 2026 09:33
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>
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.

1 participant