Configuring Root and 404 Fallback Redirects
Short domains receive requests when users access the naked hostname directly or follow broken, mistyped, or deleted links. This guide configures custom root and 404 fallback destinations so traffic never terminates on a default error screen.
Prerequisites
- Workspace permissions:
OwnerorAdminrole in your Shaf organization. - A custom domain registered in your Shaf workspace (e.g.,
go.acme.com). - Live target landing URLs for both your homepage and your help/error destination.
Implementation Recipe
Select Your Custom Domain
In the Shaf Dashboard, navigate to Settings → Domains and select your target domain to open its settings drawer, or retrieve its identifier via API:
curl -X GET "https://shaf.app/api/v1/domains" \ -H "Authorization: Bearer $SHAF_API_TOKEN"Configure Fallback Destinations
Set both redirection targets via the dashboard or dispatch a
PATCHrequest to update the domain record:curl -X PATCH "https://shaf.app/api/v1/domains/dom_01j8k3m4n5p6q7r8s9t0" \ -H "Authorization: Bearer $SHAF_API_TOKEN" \ -H "Content-Type: application/json" \ -d '{ "rootRedirect": "https://acme.com", "fallbackRedirect": "https://acme.com/404?source=shaf", "preserveQueryParams": true }'- Scroll to the Domain Routing Configuration card.
- In Root Redirect URL, enter your primary site:
https://acme.com. - In 404 Fallback URL, enter your missing-link landing page:
https://acme.com/404?source=shaf. - Enable Preserve Query Parameters to pass incoming UTM or attribution tokens to the fallback target.
- Click Save Routing Rules.
Verification
Probe both edge execution paths using curl without following redirects:
-
Test the domain root redirect:
curl -I "https://go.acme.com/"Expected output:
HTTP/2 308 Permanent Redirect location: https://acme.com x-shaf-fallback: root x-shaf-edge: HIT -
Test an unmapped 404 slug with query parameters:
curl -I "https://go.acme.com/non-existent-slug-test?utm_campaign=fallback"Expected output:
HTTP/2 302 Found location: https://acme.com/404?source=shaf&utm_campaign=fallback x-shaf-fallback: 404 x-shaf-edge: HIT
Common Gotchas
| Issue / Error | Root Cause | Solution |
|---|---|---|
| Infinite redirect loop | Root redirect URL points back to https://go.acme.com/. |
Set root redirect to a distinct domain or path (for example, https://acme.com). |
| Lost campaign attribution | preserveQueryParams is disabled, dropping incoming tracking parameters. |
Enable preserveQueryParams: true in your domain settings to forward query strings. |
| Mixed content warning | Fallback destination URL uses insecure http:// scheme. |
Always use https:// destinations in fallback configurations. |
| Inactive status error | Domain has not completed CNAME DNS verification. | Ensure the domain displays status Active before testing fallback redirects. |