Redirect Rules API
Redirect rules are the core of LinkShift routing behavior.
Base path: /api/v1/redirect-rules
Endpoints
GET /api/v1/redirect-ruleslist with cursor paginationGET /api/v1/redirect-rules/:idPOST /api/v1/redirect-rulesPUT /api/v1/redirect-rules/:idDELETE /api/v1/redirect-rules/:idGET /api/v1/redirect-rules/analyticsPOST /api/v1/redirect-rules/simulate
Critical Validation Rules
/redirect-rules validation is intentionally strict and is implemented in:
backend/src/rule-validator/rule-validator.service.ts
The validator checks, among others:
- Source regex correctness and capture-group consistency with destination references (
$1,$2, ...). - Destination URL structure and allowed schemes (
http://,https://). - Placeholder and modifier correctness (
{query.*},{domain.*},{segments.*}, etc.). - Conditional-expression syntax/operators in destination logic.
- Nested logic complexity and guardrails against excessive recursion.
- Link-map compatibility rules (
linkMapIdand destination constraints).
If validation fails, API returns 400 Bad Request with detailed error information.
Query and Path Matching
Rule matching supports:
pathMatch:exactorprefixqueryMatch:exact,ignore,subsetmatchMethod: explicit HTTP methods or empty array for all methods
Recommended Usage Pattern
- Create or update rules via API.
- Use
/simulatebefore rollout for CI/CD safety gates. - Read analytics (
/analytics) to detect unexpected traffic patterns.
Example: Create rule with explicit method and query behavior
{
"domainGroupId": "dmg_prod",
"source": "/legacy",
"destination": "https://example.com/new",
"statusCode": 308,
"matchMethod": ["GET"],
"queryMatch": "ignore",
"pathMatch": "prefix",
"priority": 50
}
