---
updatedAt: 2026-04-28T09:31:16.000Z
agentTools:
  projectIndex: https://docs.makaira.io/llms.txt
---

# Test a URL against all redirects

Test a URL against all redirects

Tests a given URL against all configured redirect rules and returns which redirect(s) would match and which one would be applied.

Requires authentication.

## Request

**`POST /redirects/debug`**

### Headers

| Header          | Value              |
| --------------- | ------------------ |
| `Authorization` | `Bearer <token>`   |
| `Content-Type`  | `application/json` |

### Request Body

| Field | Type   | Required | Description                                      |
| ----- | ------ | -------- | ------------------------------------------------ |
| `url` | string | Yes      | The URL path to test against all redirect rules. |

### Example Request

```json
{
  "url": "/old-page"
}
```

## Response

### Response Body

| Field       | Type    | Description                                                                                       |
| ----------- | ------- | ------------------------------------------------------------------------------------------------- |
| `count`     | integer | Total number of matching redirects.                                                               |
| `matched`   | object  | The redirect that would be applied (highest priority match). Contains `id`, `target`, and `code`. |
| `redirects` | array   | All matching redirects, including their `source`, `target`, `code`, `priority`, and `id`.         |

### Example Response

```json
{
  "count": 1,
  "matched": {
    "id": 42,
    "target": "/new-page",
    "code": 301
  },
  "redirects": [
    {
      "id": 42,
      "source": "/old-page",
      "target": "/new-page",
      "code": 301,
      "priority": 0
    }
  ]
}
```

### No Match

When no redirect matches the given URL:

```json
{
  "count": 0,
  "matched": null,
  "redirects": []
}
```

# OpenAPI definition

```json
{
  "openapi": "3.0.0",
  "info": {
    "title": "Makaira API",
    "version": "1.0",
    "contact": {
      "name": "Makaira GmbH",
      "url": "https://www.makaira.io/",
      "email": "support@makaira.io"
    },
    "description": "API of the powerful Makaira Search/Recommendation and Marketing Suite"
  },
  "servers": [
    {
      "url": "https://{yourinstance}.makaira.io"
    }
  ],
  "paths": {
    "/redirects/debug": {
      "post": {
        "summary": "Test a URL against all redirects.",
        "description": "Test your URL against all redirects in the database. You'll get a detailed result which redirect was selected and all other which were matched.",
        "tags": [
          "Redirects"
        ],
        "parameters": [
          {
            "$ref": "#/components/parameters/instance"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/RedirectDebugRequest"
              },
              "example": {
                "url": "/foo/bar/bar/42"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful redirect search",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedirectDebugResponse"
                },
                "example": {
                  "ok": true,
                  "results": {
                    "count": 3,
                    "matched": {
                      "target": "https://example.com/42-bar-bar",
                      "code": 301,
                      "id": 6
                    },
                    "redirects": [
                      {
                        "target": "https://example.com/42-bar-bar",
                        "code": 301,
                        "id": 6,
                        "source": "/foo/*/*/*",
                        "sourcePattern": "@^/foo/(.*)/(.*)/(.*)$@",
                        "targetPattern": "https://example.com\\/$3-$1-$2",
                        "priority": 10
                      },
                      {
                        "target": "https://example.com/42/placeholder/bar",
                        "code": 301,
                        "id": 4,
                        "source": "/foo/*/bar/*",
                        "sourcePattern": "@^/foo/(.*)/bar/(.*)$@",
                        "targetPattern": "https://example.com/$2/placeholder/$1",
                        "priority": 1
                      },
                      {
                        "target": "https://example.com/bar/bar/42/placeholder/bar/bar/42",
                        "code": 301,
                        "id": 1,
                        "source": "/foo/*",
                        "sourcePattern": "@^/foo/(.*)$@",
                        "targetPattern": "https://example.com/$1/placeholder/$1",
                        "priority": 0
                      }
                    ]
                  }
                }
              }
            }
          },
          "404": {
            "description": "There is no matching redirect",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/RedirectNotFoundError"
                },
                "example": {
                  "ok": false,
                  "message": "Can't find any suitable redirect for /foo/bar/bar/42"
                }
              }
            }
          }
        },
        "operationId": "post_redirects-debug"
      }
    }
  },
  "components": {
    "schemas": {
      "RedirectDebugRequest": {
        "type": "object",
        "properties": {
          "url": {
            "type": "string",
            "description": "The URL to test."
          }
        }
      },
      "ResolvedRedirect": {
        "type": "object",
        "properties": {
          "target": {
            "type": "string",
            "description": "The relative target link for the redirect starting with /."
          },
          "code": {
            "type": "integer",
            "description": "The http code type of the redirect (e.g. 301, 302)."
          },
          "id": {
            "type": "integer",
            "description": "ID of the matched redirect."
          }
        }
      },
      "DetailedResolvedRedirect": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ResolvedRedirect"
          },
          {
            "type": "object",
            "properties": {
              "source": {
                "type": "string",
                "description": "Source pattern of the redirect."
              },
              "sourcePattern": {
                "type": "string",
                "description": "Used regular expression to match this redirect."
              },
              "targetPattern": {
                "type": "string",
                "description": "Used pattern to create the final redirect URL."
              },
              "priority": {
                "type": "integer",
                "description": "Priority of this redirect"
              }
            }
          }
        ]
      },
      "RedirectDebugResponse": {
        "type": "object",
        "properties": {
          "count": {
            "type": "integer",
            "description": "Number of matched redirects."
          },
          "matched": {
            "type": "object",
            "description": "This is the redirect which will be used.",
            "allOf": [
              {
                "$ref": "#/components/schemas/ResolvedRedirect"
              }
            ]
          },
          "redirects": {
            "type": "array",
            "description": "All matched redirects",
            "items": {
              "allOf": [
                {
                  "$ref": "#/components/schemas/DetailedResolvedRedirect"
                }
              ]
            }
          }
        }
      },
      "RedirectNotFoundError": {
        "type": "object",
        "properties": {
          "ok": {
            "type": "boolean"
          },
          "message": {
            "type": "string"
          }
        }
      }
    },
    "parameters": {
      "instance": {
        "in": "header",
        "name": "X-Makaira-Instance",
        "required": true,
        "description": "Makaira Instance ID",
        "schema": {
          "type": "string"
        }
      }
    },
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Authentication by JSON Web Token\n"
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "x-readme": {
    "explorer-enabled": true,
    "proxy-enabled": true
  }
}
```