Repository navigation
[doc] Add a custom 404 page with absolute URLs (DOC-945) - #64603
Conversation
Read the Docs serves a docs 404 for any missing /en/<version>/... path while the browser keeps the originally requested (wrong) URL, so a 404 page built with relative hrefs can't load its own theme assets or send users back to a working page. Add a custom, themed 404 page whose <base> element pins the document base to the canonical version root (READTHEDOCS_CANONICAL_URL, falling back to html_baseurl), so every relative URL -- theme CSS/JS, the top navigation, the logo, and the recovery links -- resolves correctly regardless of the path that served the page. The <base> is injected only for the 404 page (via add_custom_assets, in block htmltitle so it precedes all asset tags). No other page's rendering is touched, which avoids the sitewide sidebar-href regression that reverted the earlier sphinx-notfound-page attempt (#63343). - doc/source/_templates/404.html: themed template (extends !layout.html) - doc/source/404.rst: :orphan: :nosearch: stub to register the docname - doc/source/_static/css/404.css: centered, theme-variable-based styles - doc/source/conf.py: 404 branch in add_custom_assets + html_sidebars Signed-off-by: Ronny Roland <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
There was a problem hiding this comment.
Code Review
This pull request introduces a custom 404 error page for the documentation, adding a dedicated Sphinx source file, a custom HTML template, and associated CSS styling. The configuration in conf.py is updated to hide the sidebar on the 404 page and dynamically resolve the base URL to ensure relative links work correctly. The review feedback identifies two key issues: first, accessing html_baseurl directly instead of via app.config can ignore command-line overrides, and a missing fallback check could cause a build crash if both canonical and base URLs are unset; second, the template uses Remix Icon classes which are not supported by the theme, so they should be replaced with Font Awesome classes to prevent broken icons.
The incremental-from-master-cache PR build path (with the DOC-1314 delete/move guard) was failing on the PR preview independently of the page content in this branch. Collapse the build.jobs.build.html override to the clean `make -C doc html` build that branch/tag builds already run, so PR previews build the same, proven way. Signed-off-by: Ronny Roland <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Swap the four hardcoded recovery-link buttons (Documentation home, Getting started, Install, Examples) for a prominent search field that opens the site-wide Algolia DocSearch modal already initialized in the navbar by sphinx-docsearch. The 404 page no longer references any content-page paths, so it can't rot into dead links when those pages move or get renamed. Also reword the lead message. Signed-off-by: Ronny Roland <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Add a sentence to the 404 lead paragraph directing users to the search box to find what they need. Signed-off-by: Ronny Roland <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Use app.config.html_baseurl (which respects -D html_baseurl= overrides) instead of the module global, and fall back to "/" so the 404 handler can't raise AttributeError if no base URL is configured. Signed-off-by: Ronny Roland <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Signed-off-by: Ronny <[email protected]>
The new-page lint rejects newly added .rst files, so author the 404 stub as MyST (.md). Faithful conversion: :orphan:/:nosearch: become frontmatter (orphan: true / nosearch: true), which MyST turns into doc metadata with no warning under -W. The docname stays "404", so the template swap in add_custom_assets and the llms_txt_exclude entry are unchanged. Verified an isolated MyST -W build stays clean and still emits 404.html with the <base> and templated body. Signed-off-by: Ronny Roland <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
dstrodtman
left a comment
There was a problem hiding this comment.
lgtm.
Just confirming: this resolves as a 404 and not a 200/300 code?
We should do follow up work to capture redirect rules that should 404 now that this is live.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit a897f4f. Configure here.
The 404 page dropped the left nav sidebar via html_sidebars but still rendered the right-hand page TOC + edit-on-github, so it didn't match the intended standalone, centered layout the way ray-overview/examples does. Add html_theme.sidebar_secondary.remove to the 404 frontmatter -- the MyST equivalent of the :html_theme.sidebar_secondary.remove: field that examples.rst and index.rst use. Flagged by Cursor Bugbot. Signed-off-by: Ronny Roland <[email protected]> Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…#64603) ## Description Adds a custom, themed **404 page** for the Ray docs. Read the Docs serves the 404 page's HTML for any missing `/en/<version>/...` URL while the browser keeps the originally requested (wrong) path. A 404 built with relative hrefs therefore can't load its own theme assets or point users to a working page. This PR gives the 404 page a `<base>` element pinned to the canonical version root (`READTHEDOCS_CANONICAL_URL`, falling back to `html_baseurl`), so every relative URL — theme CSS/JS, the top navigation, the logo, and the recovery links — resolves correctly no matter which path served the page. The `<base>` is injected **only** for the 404 page (via `add_custom_assets`, in `block htmltitle` so it precedes all asset tags). No other page's rendering is touched — which is what avoids the sitewide sidebar-href regression that caused the earlier `sphinx-notfound-page` attempt to be reverted (ray-project#63343). **Changes** (all under `doc/`): - `source/_templates/404.html` — themed template (extends `!layout.html`), injects `<base>`, custom body with recovery links - `source/404.rst` — `:orphan:` `:nosearch:` stub that registers the `404` docname - `source/_static/css/404.css` — centered layout using pydata-sphinx-theme CSS variables (light/dark aware) - `source/conf.py` — `pagename == "404"` branch in `add_custom_assets` + `"404": []` in `html_sidebars` ## Related issues Related to DOC-945. Follow-up to the reverted 404 attempt in ray-project#63343. ## Additional information Verified locally with an isolated Sphinx build (real pydata-sphinx-theme + the real template/conf logic, `READTHEDOCS_CANONICAL_URL` set to a preview host): - `<base>` present and positioned **before** all theme CSS/JS - 404 body + recovery links render; `<base>` appears on `404.html` **only** (not on any other page) **Draft pending the Read the Docs preview regression gate:** - [ ] 404 page renders with working URLs when served from a deep `/en/<version>/...` path - [ ] Other pages' `<a class="reference internal">` hrefs stay relative — `0/N` doubled `.//en/<version>/` prefixes 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Signed-off-by: Ronny Roland <[email protected]> Signed-off-by: Ronny <[email protected]> Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]> Signed-off-by: 400Ping <[email protected]>


Description
Adds a custom, themed 404 page for the Ray docs.
Read the Docs serves the 404 page's HTML for any missing
/en/<version>/...URL while the browser keeps the originally requested (wrong) path. A 404 built with relative hrefs therefore can't load its own theme assets or point users to a working page. This PR gives the 404 page a<base>element pinned to the canonical version root (READTHEDOCS_CANONICAL_URL, falling back tohtml_baseurl), so every relative URL — theme CSS/JS, the top navigation, the logo, and the recovery links — resolves correctly no matter which path served the page.The
<base>is injected only for the 404 page (viaadd_custom_assets, inblock htmltitleso it precedes all asset tags). No other page's rendering is touched — which is what avoids the sitewide sidebar-href regression that caused the earliersphinx-notfound-pageattempt to be reverted (#63343).Changes (all under
doc/):source/_templates/404.html— themed template (extends!layout.html), injects<base>, custom body with recovery linkssource/404.rst—:orphan::nosearch:stub that registers the404docnamesource/_static/css/404.css— centered layout using pydata-sphinx-theme CSS variables (light/dark aware)source/conf.py—pagename == "404"branch inadd_custom_assets+"404": []inhtml_sidebarsRelated issues
Related to DOC-945. Follow-up to the reverted 404 attempt in #63343.
Additional information
Verified locally with an isolated Sphinx build (real pydata-sphinx-theme + the real template/conf logic,
READTHEDOCS_CANONICAL_URLset to a preview host):<base>present and positioned before all theme CSS/JS<base>appears on404.htmlonly (not on any other page)Draft pending the Read the Docs preview regression gate:
/en/<version>/...path<a class="reference internal">hrefs stay relative —0/Ndoubled.//en/<version>/prefixes🤖 Generated with Claude Code