Sphinx Reredirects
Sphinx Reredirects is a Sphinx extension that generates HTML pages with meta refresh redirects for moved or renamed documentation pages, preventing 404 errors. It is currently at version 1.1.0 and is actively maintained with irregular but frequent releases.
Warnings
- breaking Version 1.0.0 introduced stricter Python and Sphinx version requirements. It now requires Python >= 3.11 and Sphinx >= 7.4.
- gotcha The extension only supports HTML-based builders (like `html` and `dirhtml`). It performs no action when building to other outputs (e.g., `linkcheck`, `latex`).
- gotcha If a source document specified in the `redirects` configuration exists, its generated HTML file will be *overwritten* by the redirect HTML. This is intentional to ensure the redirect takes precedence.
- gotcha The Sphinx `linkcheck` builder does not currently support checking redirects to other pages *within the same documentation project* when using `sphinx-reredirects`. It only checks redirects to external URLs.
- deprecated In versions prior to 0.1.6, URL fragments (e.g., `#section`) were not preserved during redirects, leading to loss of specific link targets.
Install
-
pip install sphinx-reredirects
Imports
- 'sphinx_reredirects'
extensions = ['sphinx_reredirects', ...]
Quickstart
# In your project's conf.py file:
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx_reredirects'
]
# Define your redirects. Keys are old docnames, values are new URLs.
# Docnames are paths without file extensions (e.g., 'old_chapter/intro' for 'old_chapter/intro.rst').
# Targets can be relative to the project root or absolute URLs.
redirects = {
"old-page": "new-page.html",
"removed-feature": "https://external.com/docs/new-home",
"legacy/*": "current_docs/$source.html" # Wildcard example
}
# To build the documentation and apply redirects:
# sphinx-build -M html source build