API ReferencePlatform

Rewrites

URL rewrite and redirect rules.

Prefix /cdna-api/rewrites ReferenceRewrite model GuideRewrites
Rewrites in Postman

About rewrites

A rewrite matches a request path, exactly or by regular expression, and either redirects the visitor or serves another path in its place. Rules belong to a site and are tried in order of position. The routes are irregular: a rule is created at /add-rewrite, changed and deleted on the plural /rewrites/{id}, and read only by filtering the list.

Match Exact or regex

matchType exact compares the whole path; regex takes a regular expression.

Rewrites
Action Redirect or rewrite

A redirect answers with redirectCode and the target; a rewrite serves the target under the original URL.

Custom URLs and redirects
Publishing Yes

A rule applies only once published, and a new one is unpublished by default.

Redirect mapping

List rewrites#

GET /cdna-api/rewrites/rewrites

Lists rewrites. Without limit every match comes back.

Access
Admin users and integrations, with an OAuth access token or an API key.
Model
Rewrite, in the Reference

Parameters

propertiesquery
selector
The fields and relations to return, such as {id,source,target,matchType,action,redirectCode}.
filtersquery
name=value
Any stored field, or a relation with a dot, such as parent.id=12. Prefix the name with !, >, <, % or |. Use stored field names exactly as in the model, and compare totalCount with the unfiltered list's to confirm a filter applied.
orderByquery
string
field:ASC or field:DESC, comma-separated. Stored fields only.
limitquery
integer
Records per response. There is no default.
offsetquery
integer
Records to skip.

Example

List rewrites
GET /cdna-api/rewrites/rewrites?limit=2&properties={id,source,target,matchType,action,redirectCode} HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Response 200 OK
{
  "result": "success",
  "totalCount": 42,
  "data": [
    {
      "id": 2,
      "source": "/users/login",
      "target": "/login",
      "matchType": "exact",
      "action": "rewrite",
      "redirectCode": 301
    },
    {
      "id": 3,
      "source": "/users/logout",
      "target": "/logout",
      "matchType": "exact",
      "action": "rewrite",
      "redirectCode": 301
    }
  ]
}
Open in Postman docs Real response from this documentation site

Show a rewrite#

GET /cdna-api/rewrites/rewrites

There is no route that reads one rule: GET /rewrites/rewrites/{id} answers 405. Filter the list by id instead.

Access
Admin users and integrations, with an OAuth access token or an API key.
Model
Rewrite, in the Reference

Parameters

propertiesquery
selector
The fields and relations to return, such as {id,source,target,matchType,action,redirectCode}.
filtersquery
name=value
Any stored field, or a relation with a dot, such as parent.id=12. Prefix the name with !, >, <, % or |. Use stored field names exactly as in the model, and compare totalCount with the unfiltered list's to confirm a filter applied.
orderByquery
string
field:ASC or field:DESC, comma-separated. Stored fields only.
limitquery
integer
Records per response. There is no default.
offsetquery
integer
Records to skip.

Example

Show a rewrite
GET /cdna-api/rewrites/rewrites?id=2&properties={id,source,target,matchType,action,redirectCode} HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Response 200 OK
{
  "result": "success",
  "totalCount": 1,
  "data": [
    {
      "id": 2,
      "source": "/users/login",
      "target": "/login",
      "matchType": "exact",
      "action": "rewrite",
      "redirectCode": 301
    }
  ]
}
Real response from this documentation site

Create a rewrite#

POST /cdna-api/rewrites/add-rewrite

Creates a rewrite.

Access
Admin users and integrations, with an OAuth access token or an API key.
Returns
The new rule under data.rewrite, and a message.

Parameters

sourcebody
string
The request path to match. With matchType regex, a regular expression.
targetbody
string
Where to send the visitor, or the path to serve instead.
matchTypebody
string
exact (the default) or regex.
actionbody
string
redirect (the default) sends the visitor on; rewrite serves the target under the same URL.
redirectCodebody
number
The status of a redirect: 301 (the default), 302 and so on.
publishedbody
boolean
true makes the rule apply. A new rule is unpublished unless this is sent.

Example

Create a rewrite
POST /cdna-api/rewrites/add-rewrite HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json

{
  "source": "/old-path",
  "target": "/new-path",
  "matchType": "exact",
  "action": "redirect",
  "redirectCode": 301,
  "published": true
}

Edit a rewrite#

PUT /cdna-api/rewrites/rewrites/{id}

Changes a rewrite. Fields left out keep their values.

Access
Admin users and integrations, with an OAuth access token or an API key.
Returns
The saved rule under data.rewrite, and a message.

Parameters

idpathrequired
integer
The rewrite id.
targetbody
string
Where to send the visitor, or the path to serve instead.
redirectCodebody
number
The status of a redirect: 301 (the default), 302 and so on.

Example

Edit a rewrite
PUT /cdna-api/rewrites/rewrites/1 HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json

{
  "target": "/newer-path",
  "redirectCode": 302
}

Delete a rewrite#

DELETE /cdna-api/rewrites/rewrites/{id}

Deletes a rewrite.

Access
Admin users and integrations, with an OAuth access token or an API key.

Parameters

idpathrequired
integer
The rewrite id.

Example

Delete a rewrite
DELETE /cdna-api/rewrites/rewrites/1 HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json

Delete several rewrites#

DELETE /cdna-api/rewrites/rewrites

Deletes several rules at once: their ids in ids.

Access
Admin users and integrations, with an OAuth access token or an API key.

Parameters

idsbodyrequired
list
The ids of the rules.

Example

Delete several rewrites
DELETE /cdna-api/rewrites/rewrites HTTP/1.1
Host: hub.coredna.com
Authorization: Bearer YOUR_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json

{
  "ids": [
    1,
    3
  ]
}