MkDocs Redirects Plugin
mkdocs-redirects is a plugin for MkDocs that provides dynamic page redirects, crucial for maintaining link integrity when restructuring documentation. As of version 1.2.3, it offers robust mapping capabilities for internal and external links. The project is under active development, with a recent transition to a new organizational umbrella, ProperDocs, signaling continued evolution.
Warnings
- breaking The project maintainers are transitioning to a new organization, ProperDocs, and are encouraging the use of the `properdocs` executable over the traditional `mkdocs` executable. While `mkdocs-redirects` still functions with `mkdocs`, future versions and features may prioritize the ProperDocs ecosystem.
- breaking Python 3.9 support has been officially dropped.
- gotcha Paths specified in `redirect_maps` are interpreted relative to your `docs_dir` (e.g., `docs/` by default) for the 'old path' keys. For 'new path' values, absolute paths (starting with `/`) are relative to the site root, and external URLs (starting with `http/https`) are handled directly. Relative paths in values (e.g., `../new-page.md`) are interpreted relative to the source file's location within `docs_dir`.
- gotcha If `use_directory_urls` is enabled in your `mkdocs.yml` (which is the default behavior), ensure your redirect target paths in `redirect_maps` reflect the directory-style URL structure (e.g., `new-page/` instead of `new-page.md`). Mixing styles can lead to unexpected redirect behavior.
Install
-
pip install mkdocs-redirects
Imports
-
Not imported directly in Python code. Configured via mkdocs.yml.
Quickstart
# mkdocs.yml
site_name: My Awesome Docs
plugins:
- redirects:
redirect_maps:
'old-page.md': 'new-page.md'
'blog/legacy-post.md': '/blog/current-post/' # Absolute path within site
'external-link.md': 'https://example.com/new-resource'
'docs/old-section/chapter-1.md': '../new-section/chapter-1.md' # Relative to docs_dir