Ga naar hoofdinhoud

Redirects API

De Redirects API biedt endpoints voor het beheren van URL redirects in Joomla.

Base URL

/api/index.php/v1/redirects

Endpoints Overzicht

MethodeEndpointBeschrijving
GET/redirectsAlle redirects ophalen
GET/redirects/{id}Specifieke redirect ophalen
POST/redirectsNieuwe redirect aanmaken
PATCH/redirects/{id}Redirect bijwerken
DELETE/redirects/{id}Redirect verwijderen

Alle redirects ophalen

GET /api/index.php/v1/redirects

Response

{
"data": [
{
"type": "redirects",
"id": "1",
"attributes": {
"old_url": "/oude-pagina",
"new_url": "/nieuwe-pagina",
"referer": "",
"comment": "Pagina verhuisd",
"hits": 25,
"published": 1,
"created_date": "2024-01-15 10:30:00",
"modified_date": "2024-01-15 10:30:00",
"header": 301
}
}
]
}

Specifieke redirect ophalen

GET /api/index.php/v1/redirects/{id}

Parameters

ParameterTypeBeschrijving
idintegerRedirect ID

Voorbeeld

curl -X GET "https://jouwesite.nl/api/index.php/v1/redirects/1" \
-H "X-Joomla-Token: JOUW_API_TOKEN"

Redirect aanmaken

POST /api/index.php/v1/redirects

Request Body

{
"old_url": "/oude-url",
"new_url": "/nieuwe-url",
"comment": "Pagina verplaatst naar nieuwe locatie",
"published": 1,
"header": 301
}

Verplichte velden

VeldTypeBeschrijving
old_urlstringOude URL pad
new_urlstringNieuwe URL pad

Optionele velden

VeldTypeStandaardBeschrijving
commentstring""Commentaar/notitie
publishedint1Actief (0=nee, 1=ja)
headerint301HTTP redirect code

Voorbeeld

curl -X POST "https://jouwesite.nl/api/index.php/v1/redirects" \
-H "X-Joomla-Token: JOUW_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"old_url": "/blog/oud-artikel",
"new_url": "/nieuws/nieuw-artikel",
"comment": "Blog naar nieuws verplaatst",
"header": 301
}'

Redirect bijwerken

PATCH /api/index.php/v1/redirects/{id}

Request Body

{
"new_url": "/andere-nieuwe-url",
"header": 302
}

Voorbeeld

curl -X PATCH "https://jouwesite.nl/api/index.php/v1/redirects/1" \
-H "X-Joomla-Token: JOUW_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"new_url": "/andere-url",
"comment": "URL aangepast"
}'

Redirect verwijderen

DELETE /api/index.php/v1/redirects/{id}

Voorbeeld

curl -X DELETE "https://jouwesite.nl/api/index.php/v1/redirects/1" \
-H "X-Joomla-Token: JOUW_API_TOKEN"

HTTP Redirect Codes

CodeTypeBeschrijving
301Moved PermanentlyPermanente redirect (SEO-vriendelijk)
302FoundTijdelijke redirect
303See OtherRedirect na POST request
307Temporary RedirectTijdelijk, behoudt HTTP methode
308Permanent RedirectPermanent, behoudt HTTP methode
Beste praktijk

Gebruik 301 voor permanente verhuizingen (SEO waarde wordt overgedragen) en 302 voor tijdelijke redirects.

Redirect States

WaardeStatus
-2Prullenbak
0Niet actief
1Actief
2Gearchiveerd

URL Formaat

Relatieve URLs (aanbevolen)

{
"old_url": "/oude-pagina",
"new_url": "/nieuwe-pagina"
}

Absolute URLs

{
"old_url": "https://jouwesite.nl/oude-pagina",
"new_url": "https://jouwesite.nl/nieuwe-pagina"
}

Externe redirect

{
"old_url": "/externe-link",
"new_url": "https://externe-site.nl/pagina"
}

Filtering

Op publicatiestatus

GET /api/index.php/v1/redirects?filter[published]=1

Op HTTP code

GET /api/index.php/v1/redirects?filter[header]=301

Zoeken

GET /api/index.php/v1/redirects?filter[search]=blog

Bulk Redirects Aanmaken

#!/bin/bash
# Bulk redirects aanmaken vanuit CSV

while IFS=',' read -r old new comment; do
curl -X POST "https://jouwesite.nl/api/index.php/v1/redirects" \
-H "X-Joomla-Token: JOUW_API_TOKEN" \
-H "Content-Type: application/json" \
-d "{
\"old_url\": \"$old\",
\"new_url\": \"$new\",
\"comment\": \"$comment\",
\"header\": 301
}"
done < redirects.csv

Statistieken

Elke redirect houdt het aantal hits bij in het hits veld. Dit is nuttig om te zien welke oude URLs nog steeds bezocht worden.

Meest gebruikte redirects

GET /api/index.php/v1/redirects?list[ordering]=hits&list[direction]=desc
info

Het redirect component moet ingeschakeld zijn in Joomla voor redirects om te werken. Controleer dit via System → Plugins → System - Redirect.