Skip to content

Commit 32cf7ef

Browse files
committed
add a redirect example
1 parent 7736448 commit 32cf7ef

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

deploy/reference/domains.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,30 @@ organization for use with other applications.
176176
This removes the custom domain from your organization and deletes all domain
177177
assignments across all applications.
178178

179+
## Redirecting between apex and www domains
180+
181+
If you want your site to be available on both `www.example.com` and
182+
`example.com`, we recommend serving your primary site on one of the domains and
183+
setting up a simple redirect on the other. A common pattern is to host your site
184+
on `www.example.com` and redirect all traffic from `example.com` to the `www`
185+
domain.
186+
187+
To do this:
188+
189+
1. Map `www.example.com` to your primary application.
190+
2. Create a second application and map `example.com` (the apex domain) to it.
191+
3. Deploy the following minimal program to the apex application to perform a
192+
permanent redirect (HTTP 301) to the `www` domain:
193+
194+
```ts
195+
Deno.serve(() => Response.redirect("https://www.example.com/", 301));
196+
```
197+
198+
This ensures visitors to `example.com` are permanently redirected to
199+
`https://www.example.com/`. If you prefer the opposite (redirect `www` to the
200+
apex), deploy the redirect app on `www.example.com` and point it to
201+
`https://example.com/`.
202+
179203
## Migrating a custom domain from Deploy Classic to Deno Deploy
180204

181205
If you have previously set up a custom domain on Deploy Classic and want to

0 commit comments

Comments
 (0)