Please tell me how to disable the default domain for Amplify Hosting.

Please tell me how to disable the default domain for Amplify Hosting.

Clock Icon2024.11.19

日本語版はこちら

The issue

I am using a custom domain with Amplify Hosting.
I want to restrict access to my application to only the custom domain, so please tell me how to disable the default domain amplifyapp.com.

The solution

The default domain amplifyapp.com for Amplify Hosting cannot be disabled.
As an alternative, please consider redirecting access from the default domain to the custom domain.

AWS official documentation

Redirects enable a web server to reroute navigation from one URL to another.

I tried it

I will try redirecting from the default domain amplifyapp.com to the custom domain.
The application used with Amplify Hosting has been pushed to CodeCommit.
Additionally, the custom domain to be used is an-makoto.site.

First, I will confirm that I can access the application using the default domain amplifyapp.com.
2024-09-27_15h18_43

I was able to access the application using the default domain URL.
Next, I will register the custom domain.

The domain I am using this time was obtained outside of AWS and has been registered in a Route 53 hosted zone.

2024-09-27_15h22_49

Once registered, domain verification will begin, so I will wait for a while.

After the custom domain registration is complete, I will confirm that I can access the application using the custom domain as well.

2024-09-27_15h39_37

2024-09-27_15h40_04

I was able to access the application using the custom domain as well.

Now, I will configure the settings to redirect from the default domain amplifyapp.com to the custom domain an-makoto.site.

In the Amplify console, click on "Rewrites and redirects" from the left sidebar.
2024-09-27_15h41_32

Click on "Manage redirects".
2024-09-27_15h42_37

Configure the settings as follows:

  • Source address: Default domain URL
  • Target address: Custom domain URL
  • Type: 301 (Redirect - Permanent)

2024-09-27_15h44_11

After configuring the redirect settings, access the default domain URL and confirm that it redirects to the custom domain URL.

$ curl https://main.d1lbshw0w1wpb0.amplifyapp.com -sLI | grep location
location: https://an-makoto.site/

Please note that the redirect settings are evaluated in order from top to bottom.

AWS official documentation

Redirects are applied from the top of the list down.

References

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.