Redirects

The redirects module provides the models and user interface for managing arbitrary redirection between urls and Pages or other urls.

Installation

The redirects module is not enabled by default. To install it, add wagtail.contrib.redirects to INSTALLED_APPS and wagtail.contrib.redirects.middleware.RedirectMiddleware to MIDDLEWARE in your project’s Django settings file.

INSTALLED_APPS = [
    # ...

    'wagtail.contrib.redirects',
]

MIDDLEWARE = [
    # ...
    # all other django middlware first

    'wagtail.contrib.redirects.middleware.RedirectMiddleware',
]

This app contains migrations so make sure you run the migrate django-admin command after installing.

Usage

Once installed, a new menu item called “Redirects” should appear in the “Settings” menu. This is where you can add arbitrary redirects to your site.

Page model recipe of to have redirects created automatically when changing a page’s slug, see Have redirects created automatically when changing page slug.

For an editor’s guide to the interface, see Managing Redirects.

The Redirect class

class wagtail.contrib.redirects.models.Redirect(id, old_path, site, is_permanent, redirect_page, redirect_link)
static add_redirect(old_path, redirect_to=None, is_permanent=True)

Create and save a Redirect instance with a single method.

Parameters:
  • old_path – the path you wish to redirect
  • redirect_to – a Page (instance) or path (string) where the redirect should point
  • is_permanent – whether the redirect should be indicated as permanent (i.e. 301 redirect)
Returns:

Redirect instance