aws-amplify / aws-amplify/amplify-hosting

Support redirecting specific route of a specific subdomain

Open
#773 7 comments 8 reactions 0 assignees View on GitHub
feature-request redirects
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

**Is your feature request related to a problem? Please describe.**
I'm trying to redirect a specific path of a specific subdomain to another url. The Amplify redirect rules only appear to allow redirecting every route of a subdomain or redirecting a specific route of every subdomain.

Say I have 2 subdomains `redirect.example.com` and `noredirect.example.com`. I would like
1. `redirect.example.com` and `redirect.example.com/` to **redirect** to `somemarketingdomain.com`
1. `redirect.example.com/all-other-paths`, `noredirect.example.com`, `noredirect.example.com/`, and `noredirect.example.com/all-other-paths` to **not redirect**

I think this is a feature request since I've tried a bunch of things and haven't figured it out. Here are my attempts:
1. Write redirect rule for the root path:
```json
[
{
"source": "https://redirect.example.com/",
"target": "somemarketingdomain.com",
"status": "302",
"condition": null
},
]
```
Doesn't appear to do anything and **doesn't satisfy number 1 or 2** of my requirements above.
1. Write redirect rule for every domain:
```json
[
{
"source": "/",
"target": "somemarketingdomain.com",
"status": "302",
"condition": null
},
]
```
Satisfies number 1 above but **doesn't satisfy number 2** since `noredirect.example.com` also redirects.
1. Write redirect rule for the whole subdomain:
```json
[
{
"source": "https://redirect.example.com",
"target": "somemarketingdomain.com",
"status": "302",
"condition": null
},
]
```
Satisfies number 1 above but **doesn't satisfy number 2** since `redirect.example.com/all-other-paths` also redirects.

**Describe the solution you'd like**
I would like for my attempt number 1 to work where you can redirect specific routes for a specific domain

**Additional context**
I saw that https://github.com/aws-amplify/amplify-console/issues/233#issuecomment-558835732 suggested creating a new Amplify app for each subdomain, in which case my attempt number 2 would work. But this seems like overkill and a really hacky solution with duplicate config and more room for error.

It seems like requiring one Amplify app per subdomain defeats the purpose of all the domain management features and being able to quickly change which subdomain points at which branch.

Use cases I see for this:
1. Test redirects on staging before production. I would like to test a redirect on `stage.example.com` before moving it into production at `example.com`
1. Migrating to a new domain. If I wanted to migrate incrementally from `domainone.com` to `domaintwo.com`, I could only redirect some routes until we were ready to move them all without having to create a whole separate Amplify app.
1. The ability to have a shortcode domain served from the same repo. Say I had `example.com` and `ex.app` and only wanted `ex.app` to serve `/a/123456` routes, otherwise redirect to the main app.

Contributor guide

Open the contributing guide

Research direction

The issue names no repository files or tests. Start by tracing Amplify Hosting redirect-rule and custom-domain configuration entry points, then verify how host and path matching are represented. Done means supporting a redirect for one route on one subdomain without affecting other paths or subdomains, with coverage for the listed examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws
Domain
cloud
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.