Developers

Redirect rules

Summary of redirect rule endpoints

List all available redirect rules for the current site

GET /admin/api/redirect_rules

Example response:

Status: 200 OK
[
  {
    id: 1,
    active: true,
    regexp: false,
    source: "/vanity",
    destination: "/products/handbags/connoisseur",
    redirect_type: 301,
    complexity: 1005,
    created_at: "2019-07-10T13:52:47.000Z",
    updated_at: "2019-07-10T15:24:34.000Z",
    url: "http://example.com/admin/api/redirect_rules/1"
  }
]

Parameters

  • page - requested page (default: 1).
  • per_page - elements per response (default: 50; maximum: 250).
  • search - a generic search string matching if either source or destination contains the passed value.

Filter attributes

Read more about filters.

  • Object redirect_rule attributes: id active regexp source destination redirect_type complexity created_at updated_at.

Get data for a single redirect rule

GET /admin/api/redirect_rules/1

Example response:

Status: 200 OK
{
  id: 1,
  active: true,
  regexp: false,
  source: "/vanity",
  destination: "/products/handbags/connoisseur",
  redirect_type: 301,
  complexity: 1005,
  created_at: "2019-07-10T13:52:47.000Z",
  updated_at: "2019-07-10T15:24:34.000Z",
  url: "http://example.com/admin/api/redirect_rules/1"
}

Create a new redirect rule for the current site

POST /admin/api/redirect_rules

Example data:

{
  "redirect_rule": {
    "active": true,
    "source": "/vanity",
    "destination": "/redirected",
    "redirect_type": 301
  }
}

Example response:

{
  "id": 5,
  "active": true,
  "regexp": false,
  "source": "/vanity",
  "destination": "/redirected",
  "redirect_type": 301,
  "complexity": 1009,
  "created_at": "2019-07-12T13:46:02.001Z",
  "updated_at": "2019-07-12T13:46:02.001Z",
  "url": "http://example.com/admin/api/redirect_rules/5"
}

Parameters

  • active - is the redirect rule considered on an incoming request?
  • regexp - is source a regular expression pattern?
  • source - source path or a regular expression matching a path. If a full URI is provided, only the path portion is applied.
  • destination - destination path or full URI. If regexp is true, backreferences from source may be used ($1, $2, ...)
  • redirect_type - a HTTP code for the redirection response, one of 301, 302 or 307. 410 is also allowed, but does not result in a redirect.

Update attributes of a redirect rule

PUT /admin/api/redirect_rules/1

Update the redirect rule with the provided attributes.

Example request:

PUT http://example.com/admin/api/redirect_rules/3

Example data:

{
  "redirect_rule": {
    "source": "/landing",
    "destination": "/products/hyperdrive/spring-sale",
    "redirect_type": 302
  }
}

Example response:

Status: 200 OK
{
  "id": 3,
  "active": true,
  "regexp": false,
  "source": "/landing",
  "destination": "/products/hyperdrive/spring-sale",
  "redirect_type": 302,
  "complexity": 1009,
  "created_at": "2019-07-12T13:46:02.001Z",
  "updated_at": "2019-07-12T13:46:02.001Z",
  "url": "http://example.com/admin/api/redirect_rules/3"
}

Parameters

  • active - is the redirect rule considered on an incoming request?
  • regexp - is source a regular expression pattern?
  • source - source path or a regular expression matching a path. If a full URI is provided, only the path portion is applied.
  • destination - destination path or full URI. If regexp is true, backreferences from source may be used ($1, $2, ...)
  • redirect_type - a HTTP code for the redirection response, one of 301, 302 or 307. 410 is also allowed, but does not result in a redirect.

Remove a redirect rule

DELETE /admin/api/redirect_rules/3

This request deletes the redirect rule from the database.

Example request:

DELETE http://example.com/admin/api/redirect_rules/3

Example response:

Status: 204 No Content