> ## Documentation Index
> Fetch the complete documentation index at: https://docs.aihubmix.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AWS Route 53 and Cloudfront

> Host documentation at a /docs subdirectory using AWS services

## Create Cloudfront Distribution

Navigate to [Cloudfront](https://aws.amazon.com/cloudfront) inside the AWS console and click on `Create distribution`

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/create-distribution.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=48afd08704ba180a97118bdf2267280e" alt="Cloudfront Create Distribution" width="3024" height="922" data-path="images/cloudfront/create-distribution.png" />
</Frame>

For the Origin domain, input `[SUBDOMAIN].mintlify.dev` where `[SUBDOMAIN]` is the project's unique subdomain. Click on `Use: [SUBDOMAIN].mintlify.dev`

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/origin-name.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=96839d65d811552f66c0f6ccf53c7293" alt="Cloudfront Origin name" width="3024" height="1510" data-path="images/cloudfront/origin-name.png" />
</Frame>

For **Cache key and origin requests**, select `Caching Optimized`.

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/caching-policy.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=1213bf15ad47e63aca3af882d68e6ce2" alt="Cloudfront Caching policy" width="3024" height="1322" data-path="images/cloudfront/caching-policy.png" />
</Frame>

And for **Web Application Firewall (WAF)**, enable security protections

<Frame>
  <img
    src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/enable-security-protections.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=63727e44ba1c75390eb9777d2274af2d"
    alt="Cloudfront Caching
policy"
    width="3024"
    height="1458"
    data-path="images/cloudfront/enable-security-protections.png"
  />
</Frame>

The remaining settings should be default. Click `Create distribution`.

## Add Default Origin

After creating the distribution, navigate to the `Origins` tab.

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/origins.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=cdb6f95e9b4dd2f62c29e7a16daf76ad" alt="Cloudfront Origins" width="3024" height="1466" data-path="images/cloudfront/origins.png" />
</Frame>

We want to find a staging URL that mirrors where the main domain (example.com). This is highly variant depending on how your landing page is hosted.

<Info>
  For instance, if your landing page is hosted on Webflow, you can use the
  Webflow's staging URL. It would look like `.webflow.io`.

  If you use Vercel, you use the `.vercel.app` domain available for every project.
</Info>

<Note>
  If you're unsure on how to get a staging URL for your landing page, [contact
  support](mailto:support@mintlify.com) and we'd be happy to help
</Note>

Once you have the staging URL, ours for instance is [mintlify-landing-page.vercel.app](https://mintlify-landing-page.vercel.app), create a new Origin and add it as the **Origin domain**.

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/default-origin.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=de5a8186d534161fda3a0eb2d11d7145" alt="Cloudfront Default Origins" width="3024" height="1332" data-path="images/cloudfront/default-origin.png" />
</Frame>

By this point, you should have two Origins - one with `[SUBDOMAIN].mintlify.app` and another with with staging URL.

## Set Behaviors

Behaviors in Cloudfront enables control over the subpath logic. At a high level, we're looking to create the following logic.

* **If a user lands on /docs**, go to `[SUBDOMAIN].mintlify.dev`
* **If a user lands on any other page**, go the current landing page

We're going to create three behaviors by clicking on the `Create behavior` button.

### `/docs/*`

The first behavior should have a **Path pattern** of `/docs/*` with **Origin and origin groups** pointing to the `.mintlify.dev` URL (in our case `acme.mintlify.dev`)

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/behavior-1.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=89f52fe382ce934a44517e39e303e9bb" alt="Cloudfront Behavior 1" width="3024" height="1288" data-path="images/cloudfront/behavior-1.png" />
</Frame>

For **Cache policy**, select `CachingOptimized` and create behavior.

### `/docs`

The second behavior should be the same as the first one but with a **Path pattern** of `/docs` and **Origin and origin groups** pointing to the same `.mintlify.dev` URL.

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/behavior-2.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=332414ebb81db921514c08805f230980" alt="Cloudfront Behavior 2" width="3024" height="1284" data-path="images/cloudfront/behavior-2.png" />
</Frame>

### `Default (*)`

Lastly, we're going to edit the `Default (*)` behavior.

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/default-behavior-1.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=676ac90cb4eeea5f6a0489b942174bae" alt="Cloudfront Behavior Default 1" width="3024" height="1406" data-path="images/cloudfront/default-behavior-1.png" />
</Frame>

We're going to change the default behavior's **Origin and origin groups** to the staging URL (in our case `mintlify-landing-page.vercel.app`).

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/default-behavior-2.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=297cb6ad8dc03ab608ba6a357cb2e572" alt="Cloudfront Behavior Default 2" width="3024" height="1298" data-path="images/cloudfront/default-behavior-2.png" />
</Frame>

Click on `Save changes`.

## Preview Distribution

You can now test if your distribution is set up properly by going to the `General` tab and visiting the **Distribution domain name** URL.

<Frame>
  <img
    src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/preview-distribution.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=548e80deb6d7f10d7aa93bd839868659"
    alt="Cloudfront Preview
distribution"
    width="3024"
    height="1394"
    data-path="images/cloudfront/preview-distribution.png"
  />
</Frame>

All pages should be directing to your main landing page, but if you append `/docs` to the URL, you should see it going to the Mintlify documentation instance.

## Connecting it with Route53

Now, we're going to bring the functionality of the Cloudfront distribution into your primary domain.

<Note>
  For this section, you can also refer to AWS's official guide on [Configuring
  Amazon Route 53 to route traffic to a CloudFront
  distribution](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-cloudfront-distribution.html#routing-to-cloudfront-distribution-config)
</Note>

Navigate to [Route53](https://aws.amazon.com/route53) inside the AWS console, and click into the `Hosted zone` for your primary domain. Click on `Create record`

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/route53-create-record.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=7ac0f9c0acc8398316a1a4ad9acdec57" alt="Route 53 create record" width="1540" height="1238" data-path="images/cloudfront/route53-create-record.png" />
</Frame>

Toggle `Alias` and then **Route traffic to** the `Alias to CloudFront distribution` option.

<Frame>
  <img src="https://mintcdn.com/aihubmix/2nT-vfHReUtOnhMv/images/cloudfront/create-record-alias.png?fit=max&auto=format&n=2nT-vfHReUtOnhMv&q=85&s=3bf1f6ce5f8e7a66b94d51c5c4e8bad3" alt="Route 53 create record alias" width="3024" height="1494" data-path="images/cloudfront/create-record-alias.png" />
</Frame>

Click `Create records`.

<Note>
  You may need to remove the existing A record if one currently exists.
</Note>

And voila! You should be able to have your documentation served at `/docs` for your primary domain.
