---
title: "Configuring Root and 404 Fallback Redirects"
description: "Define custom destination URLs for root visits and unmapped 404 slugs on branded short domains."
---

> Documentation Index
> Fetch the complete documentation index at: https://shaf.app/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Configuring Root and 404 Fallback Redirects

# 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: `Owner` or `Admin` role 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

1. **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:

   ```bash
   curl -X GET "https://shaf.app/api/v1/domains" \
     -H "Authorization: Bearer $SHAF_API_TOKEN"
   ```
2. **Configure Fallback Destinations**

   Set both redirection targets via the dashboard or dispatch a `PATCH` request to update the domain record:

   ### cURL / API

   ```bash
   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
     }'
   ```

   ### Dashboard

   1. Scroll to the **Domain Routing Configuration** card.
   2. In **Root Redirect URL**, enter your primary site: `https://acme.com`.
   3. In **404 Fallback URL**, enter your missing-link landing page: `https://acme.com/404?source=shaf`.
   4. Enable **Preserve Query Parameters** to pass incoming UTM or attribution tokens to the fallback target.
   5. Click **Save Routing Rules**.

   > **Edge Cache Propagation**
   >
   > Routing modifications update Cloudflare Anycast KV immediately. Propagation across all edge data centers takes under 5 seconds.

---

## Verification

Probe both edge execution paths using `curl` without following redirects:

1. Test the domain root redirect:
   ```bash
   curl -I "https://go.acme.com/"
   ```
   **Expected output:**
   ```http
   HTTP/2 308 Permanent Redirect
   location: https://acme.com
   x-shaf-fallback: root
   x-shaf-edge: HIT
   ```

2. Test an unmapped 404 slug with query parameters:
   ```bash
   curl -I "https://go.acme.com/non-existent-slug-test?utm_campaign=fallback"
   ```
   **Expected output:**
   ```http
   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. |

Source: https://shaf.app/docs/how-to/domains-and-branding/root-and-fallback-redirects/index.mdx
