# How to set up 301 redirects without redeploying your website

Gregale · Updated 2026-12-01

Move an old URL with a Gregale edge redirect, verify the exact Location in one hop, and confirm the serving deployment did not change.

You can redirect an old URL without redeploying your website by putting a permanent HTTP redirect at the edge. On Gregale, match the old hostname and path, then return `301` with a `Location` header pointing directly to the replacement. The redirect runs before the request reaches your app.

[Download the runnable example](https://gregale.dev/examples/301-redirects-without-redeploying.zip)

## 1. Map the old URL to its replacement

Start with a real destination, not a catch-all to the homepage. For this example, `/pricing-old` moves to `/pricing`. Check that the destination serves the expected page first. If you have many URLs, make a one-to-one map for important pages. If a page is gone and has no replacement, a 404 or 410 is usually more honest than redirecting every visitor to the homepage. See [Google’s site-move guidance](https://developers.google.com/search/docs/crawling-indexing/site-move-with-url-changes).

When moving between hostnames, keep control of the old hostname and its HTTPS certificate. DNS only tells the browser where to connect; it cannot send a page-level HTTP redirect. Treat a whole-domain or `www` move as a separate exercise: test nested paths, any query parameters you need to preserve, and your CDN in addition to the rule below.

## 2. Add a 301 at the edge

The downloaded sample serves `/pricing` and `/privacy`, with no redirect in the app. Deploy it once to a new disposable app with the [Gregale CLI](https://gregale.dev/docs/install.md), or adapt the rule to a hostname you already control.

```bash
APP='replace-with-a-new-demo-app'
gregale deploy --name "$APP" --source=worktree
HOST='replace-with-the-host-printed-by-deploy'
gregale --json release traffic status "$APP"
```

Record the deployment ID listed at 100% traffic. For the actual redirect, match only the old path on that hostname, for GET and HEAD:

```bash
gregale edge rule create --app "$APP" --kind redirect \
  --match-host "$HOST" --match-path /pricing-old \
  --match-method GET --match-method HEAD \
  --redirect-status 301 --redirect-to "https://$HOST/pricing"
```

Save the rule ID. This rule uses a fixed destination and does not preserve the incoming query string. A permanent redirect can be cached by browsers; test with a 302 first on a real migration if the mapping is still being reviewed. If you need to preserve the HTTP method and body, use 308 for a permanent move and test clients accordingly. See [Gregale’s redirect rule reference](https://gregale.dev/docs/edge-rules.md#redirect).

## 3. Check the redirect and the serving release

Check the old path without following it. This exposes the first response and avoids hiding a chain.

```bash
curl -sS -D - -o /dev/null "https://$HOST/pricing-old"
curl -fsS "https://$HOST/pricing"
curl -fsS "https://$HOST/privacy"
gregale --json release traffic status "$APP"
```

If your app requires authentication, use its normal credentials for each owned URL separately; do not forward credentials through a redirect. The first response should be **301** with `Location: https://YOUR_HOST/pricing`. The exact target should return **200** and the pricing page, not another redirect. The privacy page should still respond with its original content. Finally, the original deployment ID should still be serving traffic.

If the mapping is wrong, fix the rule or remove that exact rule with `gregale edge rule delete RULE_ID --app "$APP"`. That stops it at the edge, but a previously cached permanent redirect can outlive the rule. On a real site move, also update internal links, canonicals and the sitemap to use the final URLs.

## Hosted test results

We deployed the sample once to a disposable private Gregale app on Scale. Authenticated GETs produced these results:

| Path           | Before the edge rule | After the edge rule             |
| -------------- | -------------------- | ------------------------------- |
| `/pricing-old` | 404                  | 301 to the exact `/pricing` URL |
| `/pricing`     | 200                  | 200 with identical content      |
| `/privacy`     | 200                  | 200 with identical content      |

The deployment list was unchanged, and the same deployment UUID remained at 100% traffic after the rule took effect. We checked one hop on the Gregale app hostname; we did not test anonymous ingress, a custom-domain migration, or indexing.

For a custom hostname that isn’t ready, see [how to diagnose pending DNS or HTTPS](https://gregale.dev/articles/custom-domain-stuck-pending-dns-ssl).

## Questions

### Can I set up a 301 redirect without deploying new code?

Yes. An edge redirect rule can return HTTP 301 and a fixed Location for an exact hostname and path without calling your app or creating a new deployment.

### How do I verify a permanent redirect after a site migration?

Request the old URL without following redirects, check the 301 and exact Location header, then fetch the target and confirm it serves the expected page without another redirect.

### Can DNS alone redirect a website path?

No. DNS resolves hostnames. Use an HTTP edge or server redirect to send visitors from an old URL path to its new destination.

Canonical URL: https://gregale.dev/articles/301-redirects-without-redeploying

