Skip to content

v0.24 - better redirects for multi-site setups

Compare
Choose a tag to compare
@kbayliss kbayliss released this 05 Jan 17:10
· 18 commits to main since this release

This release makes working with redirects in multi-site setups easier by adding more details. It:

  • Exposes the site field.
  • Supports redirects without a new_url or page thus making HTTP 410 handling possible.
  • Returns one result per associated site.

Warning

This is a breaking change release.

  • The new_url in results now takes into account the Redirect site. Previously, this would always use BASE_URL (from the settings file)
  • Redirects that apply to all sites (i.e. not associated with a specific site) now appear multiple times when querying - one for each Site created in Wagtail.

Upgrade considerations

In a multi-site setup, you should add the site field to any redirect queries to help disambiguate between redirects that apply to all sites.

For example, given we have two Sites created in Wagtail:

  1. https://www.example.com
  2. https://www.another-example.com

and a single Redirect from old-path to new-path that is not associated with any specific site (and thus applies to all sites).

Previously, querying for a redirect:

{
  redirects {
    newUrl
    oldUrl
    oldPath
    page {
      id
    }
    isPermanent
  }
}

would produce:

{
  "data": {
    "redirects": [
      {
        "isPermanent": true,
        "newUrl": "http://www.example.com/new-path",
        "oldPath": "/old-path",
        "oldUrl": "http://www.example.com/old-path",
        "page": null
      }
    ]
  }
}

which excludes the redirect that applies to https://www.another-example.com.

As of this release, the same query would produce:

{
  "data": {
    "redirects": [
      {
        "isPermanent": true,
        "newUrl": "http://www.example.com/new-path",
        "oldPath": "/old-path",
        "oldUrl": "http://www.example.com/old-path",
        "page": null,
      },
      {
        "isPermanent": true,
        "newUrl": "http://www.another-example.com/new-path",
        "oldPath": "/old-path",
        "oldUrl": "http://www.another-example.com/old-path",
        "page": null,
      }
    ]
  }
}

To disambiguate the results, you should add site to your query, for example:

{
  redirects {
    newUrl
    oldUrl
    oldPath
    page {
      id
    }
    isPermanent
    site {
      hostname
    }
  }
}

which would return:

{
  "data": {
    "redirects": [
      {
        "isPermanent": true,
        "newUrl": "http://www.example.com/new-path",
        "oldPath": "/old-path",
        "oldUrl": "http://www.example.com/old-path",
        "page": null,
        "site": {
          "hostname": "www.example.com"
        }
      },
      {
        "isPermanent": true,
        "newUrl": "http://www.another-example.com/new-path",
        "oldPath": "/old-path",
        "oldUrl": "http://www.another-example.com/old-path",
        "page": null,
        "site": {
          "hostname": "www.another-example.com"
        }
      }
    ]
  }
}

What's Changed

New Contributors

Full Changelog: v0.23.0...v0.24.0