New in 2.4: Test runs you can trust See what's new →

Redirects to a local path on this server

GETPOSTPUTPATCHDELETEHEADhttps://api.testingapis.com/api/redirect/to

Accepts GET, POST, PUT, PATCH, DELETE and HEAD.

Parameters 2

NameTypeDescription
urlquery · stringTarget path. It must start with a single / (e.g. /api/echo?x=1) and be at most 2048 characters. Absolute URLs, //host, /\host and control characters are rejected to prevent open redirects.
statusquery · integer (int32)Redirect status: 301, 302, 303, 307 or 308. Default 302. Default: 302.

Responses

200
OK
302
Or the chosen redirect status, with Location set to url.
400
Missing or non-local url, or unsupported status.

Example

Request
curl -X GET "https://api.testingapis.com/api/redirect/to?url=/api/echo&status=302"
Run in Studio
Response302 Found
Location: /api/echo

{
  "status": 302,
  "statusText": "Found",
  "location": "/api/echo",
  "remaining": null,
  "keepsMethod": false
}

Code examples

JavaScript (fetch)
const response = await fetch("https://api.testingapis.com/api/redirect/to?url=/api/echo&status=302");
console.log(response.status, await response.text());
Python (requests)
import requests

response = requests.request(
    "GET",
    "https://api.testingapis.com/api/redirect/to?url=/api/echo&status=302",
    allow_redirects=False,
)
print(response.status_code, response.text)
Java (HttpClient)
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class Main {
    public static void main(String[] args) throws Exception {
        HttpClient client = HttpClient.newBuilder()
            .followRedirects(HttpClient.Redirect.NEVER)
            .build();

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create("https://api.testingapis.com/api/redirect/to?url=/api/echo&status=302"))
            .method("GET", HttpRequest.BodyPublishers.noBody())
            .build();

        HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
        System.out.println(response.statusCode() + " " + response.body());
    }
}