---
title: "Handles requests to the `/redirect/:n` endpoint."
url: "https://developer.rucho.org/apis/rucho/versions/5bdf1bcb-8db4-40f1-a293-72c7198e26c8/operations/redirect_handler"
---

> Full API specification: https://developer.rucho.org/apis/rucho/versions/5bdf1bcb-8db4-40f1-a293-72c7198e26c8.md

# Handles requests to the `/redirect/:n` endpoint.

`HEAD` `/redirect/{n}`

Operation ID: `redirect_handler`

Returns a 302 redirect chain that decrements `n` on each hop. When `n` reaches 1, redirects to `/get` as the final destination. When `n` is 0, returns 200 directly (redirect complete). # Security The maximum number of hops is capped at `MAX_REDIRECT_HOPS` (20) to prevent abuse through excessively long redirect chains.

## Path parameters

- `n` (integer, int32, required) - Number of redirects remaining (max 20)

## Responses

- `200` - Redirect complete (when n=0)
- `302` - Redirects to /redirect/{n-1} or /get when n=1
- `400` - Redirect count exceeds maximum allowed value

## OpenAPI definition

```yaml
openapi: 3.0.3
info:
  title: rucho
  version: 1.6.0
servers:
  - url: https://rucho.org
    description: Production (EKS us-east-2, behind Kong)
paths:
  /redirect/{n}:
    head:
      tags:
        - crate::routes::redirect
      summary: Handles requests to the `/redirect/:n` endpoint.
      description: >-
        Returns a 302 redirect chain that decrements `n` on each hop.

        When `n` reaches 1, redirects to `/get` as the final destination.

        When `n` is 0, returns 200 directly (redirect complete).


        # Security


        The maximum number of hops is capped at `MAX_REDIRECT_HOPS` (20) to
        prevent

        abuse through excessively long redirect chains.
      operationId: redirect_handler
      parameters:
        - name: n
          in: path
          description: Number of redirects remaining (max 20)
          required: true
          schema:
            type: integer
            format: int32
            minimum: 0
      responses:
        "200":
          description: Redirect complete (when n=0)
          content:
            text/plain:
              schema:
                type: string
        "302":
          description: Redirects to /redirect/{n-1} or /get when n=1
        "400":
          description: Redirect count exceeds maximum allowed value
```
