Skip to content

amplify url won't redirect to our domain

0

Hi. I've got 3 amplify apps. One (core) is responsible for the domain routing. The other 2 (motorhome, surf) have an issue where redirects from the default amplify url to our custom domain don't work. This is what we have in motorhome rules (similar for the surf site). Sites are used together:

[
  {
    "source": "/motorhome/<*>",
    "status": "200",
    "target": "/<*>"
  }
]

This allows the motorhome app to work but requests to the amplify url are simply responded with the source from the motorhome app. We need it to redirect to https://www.ourdomain.nz/motorhome/

We have tried many redirect type rules and the closest we came to it working was an endless redirect loop by using this type of thing:

{
    "source": "https://main.[motorhome-app-id].amplifyapp.com",
    "status": "301",
    "target": "https://www.ourdomain.nz/motorhome/"
  },
  {
    "source": "/motorhome/<*>",
    "status": "200",
    "target": "/<*>"
  }

What are we doing wrong?

Our core site has the following set of rules with a redirect in cloudflare so that all domain requests are redirected to www.ourdomain.nz:

[
  {
    "source": "https://main.[core-app-id].amplifyapp.com",
    "status": "301",
    "target": "https://www.ourdomain.nz"
  },
  {
    "source": "/motorhome/<*>",
    "status": "200",
    "target": "https://main.[motorhome-app-id].amplifyapp.com/<*>"
  },
  {
    "source": "/surf/<*>",
    "status": "200",
    "target": "https://main.[surf-app-id].amplifyapp.com/<*>"
  },
  {
    "source": "/<*>",
    "status": "404-200",
    "target": "/index.html"
  }
]

all websites can be accessed like so: https://www.ourdomain.nz (works fine) https://www.ourdomain.nz/motorhome/ (works fine) https://www.ourdomain.nz/surf/ (works fine) and are working fine. Requesting the amplify url for core redirects to https://www.ourdomain.nz as it should, but using the amplify urls for the other two apps do not redirect to our domain versions.

Thanks.

asked a year ago349 views

2 Answers
0

It appears you're experiencing an issue with redirecting from your Amplify app URLs to your custom domain for your motorhome and surf applications.

The issue seems to be in how you've configured your redirect rules. When trying to redirect from the Amplify app URL to your custom domain, you need to ensure both the domain configuration and redirect rules are properly set up.

For your motorhome and surf apps, you should:

  1. Make sure both the root domain and www subdomain are added in the Amplify domain management settings for each app. This is crucial for proper redirection.

  2. In your redirect rules, you need to modify how you're targeting the Amplify URLs. The format you're using for source may not be matching correctly. Instead of using the full URL in the source, try using patterns that match the path:

[
{
"source": "/<*>",
"status": "301",
"target": "https://www.ourdomain.nz/motorhome/<*>"
}
]
  1. Check that your custom domain is correctly configured in AWS Amplify and that DNS settings are properly propagated. This includes verifying that the CNAME records are correctly set up in your DNS provider.

  2. If you're still experiencing issues, try invalidating the cache in AWS Amplify Console, as caching can sometimes cause redirect issues to persist even after configuration changes.

  3. Ensure that the SSL certificates for your domains are correctly configured and active.

The endless redirect loop you experienced suggests that your rules might be creating a circular reference. Make sure your rules are specific enough to avoid this situation.
Sources
Root domain redirection is not working on AWS Amplify with a custom domain. | AWS re:Post
Issue with AWS Amplify Deployment on Custom Domain | AWS re:Post
I getting the 301 issue while deploy my code in the aws amplify | AWS re:Post
Amplify custom domain setup issue | AWS re:Post

answered a year ago

  • Can we have some human help please?

0

Make sure both the root domain and www subdomain are added in the Amplify domain management settings for each app

I haven't found a "domain management settting", so I assume you mean Custom domains? It appears that the same domain can not be added to multiple apps. We have it added to the core app, but attempting to add it to motorhome and surf apps are responded to in the console with One or more domains requested are already associated with another Amplify app: ourdomain.nz, www.ourdomain.nz and are not allowed to add the domain.

This is crucial for proper redirection.

How do we go about getting "proper redirection" if you won't allow us to add it?

In your redirect rules, you need to modify how you're targeting the Amplify URLs. The format you're using for source may not be matching correctly. Instead of using the full URL in the source, try using patterns that match the path:

We tried this.

Check that your custom domain is correctly configured in AWS Amplify

We've done this in core, as mentioned above, we are unable to add the same domain to the sub sites, if we had not done it, then the following domains would not be working: https://www.ourdomain.nz (works fine) https://www.ourdomain.nz/motorhome/ (works fine) https://www.ourdomain.nz/surf/ (works fine)

and that DNS settings are properly propagated

If this wasn't the case then the following would not be working: https://www.ourdomain.nz (works fine) https://www.ourdomain.nz/motorhome/ (works fine) https://www.ourdomain.nz/surf/ (works fine)

This includes verifying that the CNAME records are correctly set up in your DNS provider.

I think if the CNAME records were not properly setup in our DNS provider (CloudFlare) then the following would not be working: https://www.ourdomain.nz (works fine) https://www.ourdomain.nz/motorhome/ (works fine) https://www.ourdomain.nz/surf/ (works fine)

If you're still experiencing issues, try invalidating the cache in AWS Amplify Console

We haven't found this feature in the console, so we used invalidation in customHttp.yml files in the root of each app:

  - pattern: "*"
    headers:
      - key: 'Cache-Control'
        value: 'no-store, no-cache, max-age=0, must-revalidate'

We also have the Caching - Configuration in CloudFlare set to Browser Cache TTL 1 second, Development Mode on, and we also Purge Everything after: each change in amplify app and redeploy.

as caching can sometimes cause redirect issues to persist even after configuration changes.

We have been able to see our changes take effect, because things just break.

Ensure that the SSL certificates for your domains are correctly configured and active.

I'm not sure what SSL certs have to do with this, I'm pretty sure if they were not configured and active, then the following URLs would not be working: https://www.ourdomain.nz (works fine) https://www.ourdomain.nz/motorhome/ (works fine) https://www.ourdomain.nz/surf/ (works fine)

After the suggested change (other than the adding of ourdomain.nz and www.ourdomain.nz to Custom domains for motorhome and surf apps because the console won't allow it), when we try fetch https://main.[motorhome-app-id].amplifyapp.com we get: ERR_TOO_MANY_REDIRECTS in the browser. The browser network tools Initiator looks like: Request initiator chain https://www.ourdomain.nz/motorhome/ https://www.ourdomain.nz/motorhome/ https://www.ourdomain.nz/motorhome/ https://www.ourdomain.nz/motorhome/ https://www.ourdomain.nz/motorhome/ etc...

So as you can see, the same issue persists.

The endless redirect loop you experienced suggests that your rules might be creating a circular reference. Make sure your rules are specific enough to avoid this situation.

We used the rule you suggested, and... as you can see, the same issue persists. So... What are we doing wrong?

answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.