App Platform does not support 301
or 302
responses to direct traffic from one domain to another, but you can create a free blank app with a custom domain that redirects the app’s traffic to another app’s domain.
To do this, download the following spec to your local machine and save it as redirect.yaml
.
alerts:
- rule: DEPLOYMENT_FAILED
- rule: DOMAIN_FAILED
domains:
- domain: www.example.com
type: PRIMARY
features:
- buildpack-stack=ubuntu-22
ingress:
rules:
- match:
path:
prefix: /
redirect:
authority: example.com
redirect_code: 302
name: domain-redirect
region: lon
Then update the domain
field with the domain you want to direct from and the authority
field with the target domain that you want to direct traffic to. In that sample spec, the domain www.example.com
redirects to example.com
.
Once you have updated the spec file, you can pass the spec to the App Platform using doctl
, DigitalOcean’s official CLI.
To pass the spec to App Platform using doctl
, run the following command from the same directory where you saved the spec file:
doctl apps create --spec redirect.yaml
App Platform creates the app with the redirect.