Help centerRoutes, headers & scripts
Routes
Create friendly paths on the customer's domain that show (rewrite) or send visitors to (redirect) another path of your app, project-wide or for a single domain.
Routes connect a path on the customer's domain to a path in your app. With them, customer.com/book can show your
app's /booking screen without the visitor noticing, or customer.com/promo can send people to
/plans?coupon=PROMO. They apply to every domain in the project or to a single domain.
How it works
Each route has a Path on the domain (what the visitor opens), a Path on the origin (what your app receives) and a Mode:
- a route matches the exact path and everything below it: with
/blog→/articles, opening/blog/tipsgets/articles/tips; - the
/route only matches the home page (it doesn't capture the rest of the site); - if more than one route matches, the most specific one wins (
/courses/freebeats/courses); - case matters:
/Bookand/bookare different paths; - the destination may carry parameters (
/plans?coupon=PROMO), but it's always a path in your app, never another site.
Rewrite or redirect
| Mode | What the visitor sees | URL parameters |
|---|---|---|
| Rewrite (masked URL) | The address bar keeps the domain path (/book); the content comes from the origin path |
The destination's win over the visitor's |
| Redirect (302) | The browser is sent to the destination path, on the same customer domain (customer.com/booking) |
The visitor's win over the destination's |
Use Rewrite for friendly URLs and to hide your app's structure. Use Redirect when the address really needs to change (for example, so a SPA router finds the right screen; see SPA apps).
Built-in safeguards:
- a route whose destination has the same path (e.g.
/→/?ref=partner) never redirects, so it can't loop: it just adds the parameters; - a route never gives access to a blocked path: if the destination is blocked, the visitor gets
a
403; - redirects apply to
GETrequests (opening pages);POST,PUTand the like (forms, calls that send data) are always rewritten.
Creating a route
- Open the project and go to the Customization tab;
- On the Routes tab, click Add route;
- Fill in Path on the domain (e.g.
/book) and Path on the origin (e.g./booking). Both start with/; - Pick the Mode: Rewrite (masked URL) or Redirect (302);
- Click Add route. The route goes live within seconds on every domain in the project.
To change a route, edit its fields and click Save. To delete it, use the trash icon and confirm.
Project and domain (inheritance)
Project routes apply to all of its domains. A domain can have its own configuration instead:
- Open the domain and go to the Customization tab;
- In the Routes card, turn the switch on (the label changes from Inheriting from project to Own settings);
- Create this domain's routes right there with Add route.
With own configuration, the domain uses only its own routes: the project's no longer apply to it (including ones created later). Turn the switch off and the project's routes apply again; the domain's are kept, with no effect. While inheriting, the card shows the project's routes (read-only) and an Edit in project link.
You can also tick Use its own configuration when adding the domain; it then starts with its own routes, headers and scripts.
Via the API
| What | Operation |
|---|---|
| List / create project routes | GET / POST /projects/:id/rules/routes |
| List / create domain routes | GET / POST /domains/:id/rules/routes |
Change (fields, enabled, position) |
PATCH /rules/routes/:ruleId |
| Delete | DELETE /rules/routes/:ruleId |
| Turn on a domain's own configuration | PATCH /domains/:id with overrides |
mode is rewrite (default) or redirect.
curl -X POST https://api.tenanci.com/v2/projects/prj_8f3k2m/rules/routes \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"source":"/book","destination":"/booking","mode":"rewrite"}'await tenanci.request("POST", "/projects/prj_8f3k2m/rules/routes", {
source: "/book",
destination: "/booking",
mode: "rewrite",
});For a domain to use its own routes, include routes in overrides and create the rules on the domain. overrides
replaces the whole list (routes, headers, injections), so send every section the domain should override:
curl -X PATCH https://api.tenanci.com/v2/domains/dom_4h7n1q \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"overrides":["routes"]}'
curl -X POST https://api.tenanci.com/v2/domains/dom_4h7n1q/rules/routes \
-H "Authorization: Bearer tnc_live_xxxxxxxx_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{"source":"/book","destination":"/booking/downtown"}'await tenanci.domains.update("dom_4h7n1q", { overrides: ["routes"] });
await tenanci.request("POST", "/domains/dom_4h7n1q/rules/routes", {
source: "/book",
destination: "/booking/downtown",
});
