Skip to main content

mkdocs-redirects

Plugin for mkdocs to create page redirects (e.g. for moved/renamed pages).

Initially developed by DataRobot.

Installing

Note: This package requires MkDocs version 1.0.4 or higher.

Install with pip:

pip install mkdocs-redirects

Using

To use this plugin, specify your desired redirects in the plugin's redirect_maps setting in your mkdocs.yml:

plugins:
    - redirects:
        redirect_maps:
            'old.md': 'new.md'
            'old/file.md': 'new/file.md'
            'some_file.md': 'http://external.url.com/foobar'

Note: don't forget that specifying the plugins setting will override the defaults if you didn't already have it set! See this page for more information.

The redirects map should take the form of a key/value pair:

  • The key of each redirect is the original markdown doc (relative to the docs_dir path).
    • This plugin will handle the filename resolution during the mkdocs build process. This should be set to what the original markdown doc's filename was (or what it would be if it existed), not the final HTML file rendered by MkDocs
  • The value is the redirect target. This can take the following forms:
    • Path of the markdown doc you wish to be redirected to (relative to docs_dir)
      • This plugin will handle the filename resolution during the mkdocs build process. This should be set to what the markdown doc's filename is, not the final HTML file rendered by MkDocs
    • External URL (e.g. http://example.com)

During the mkdocs build process, this plugin will create .html files in site_dir for each of the "old" file that redirects to the "new" path. It will produce a warning if any problems are encountered or of the redirect target doesn't actually exist (useful if you have strict: true set).

use_directory_urls

If you have use_directory_urls: true set (which is the default), this plugin will modify the redirect targets to the directory URL, not the actual index.html filename. However, it will create the index.html file for each target in the correct place so URL resolution works.

For example, a redirect map of 'old/dir/README.md': 'new/dir/README.md' will result in an HTML file created at $site_dir/old/dir/index.html which redirects to ../../new/dir/.

Additionally, a redirect map of 'old/dir/doc_name.md': 'new/dir/doc_name.md' will result in $site_dir/old/dir/doc_name/index.html redirecting to ../../new/dir/doc_name/.

This mimics the behavior of how MkDocs builds the site dir without this plugin.

Developing

Setup a virtualenv

Create a virtualenv using a method of your choice.

brew install pyenv pyenv-virtualenv
pyenv install 2.7.18
pyenv virtualenv 2.7.18 mkdocs-redirects
pyenv activate mkdocs-redirects

Build

make build

Test

make test

Releasing

make release

It will prompt you for your PyPI user and password.

See:

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mkdocs-redirects-1.2.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mkdocs_redirects-1.2.1-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file mkdocs-redirects-1.2.1.tar.gz.

File metadata

  • Download URL: mkdocs-redirects-1.2.1.tar.gz
  • Upload date:
  • Size: 6.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.28.1 requests-toolbelt/0.9.1 urllib3/1.26.12 tqdm/4.63.1 importlib-metadata/6.8.0 keyring/23.9.3 rfc3986/1.5.0 colorama/0.4.6 CPython/3.10.10

File hashes

Hashes for mkdocs-redirects-1.2.1.tar.gz
Algorithm Hash digest
SHA256 9420066d70e2a6bb357adf86e67023dcdca1857f97f07c7fe450f8f1fb42f861
MD5 fc2c6cd1cc9a5d4a546af778a1a7af57
BLAKE2b-256 046a50edd7ad78042b25c379aac7e8fa9cc34c6f55e3d2c03eb28814a9446617

See more details on using hashes here.

File details

Details for the file mkdocs_redirects-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for mkdocs_redirects-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 497089f9e0219e7389304cffefccdfa1cac5ff9509f2cb706f4c9b221726dffb
MD5 8d84f05a313ca1dec13eb3296e425e2d
BLAKE2b-256 d39d93a881fc5a23c50a4dd4a41dfd3d2a8403aa1dac52370ef43b7b336577a0

See more details on using hashes here.

Release history Release notifications | RSS feed

1.2.3

2 files

1.2.2

2 files

This release

1.2.1 This release

2 files

1.2.0

1 file

1.1.0

1 file

1.0.6

1 file

1.0.5

1 file

1.0.4

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

1 file

0.0.6

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page