aws-amplify / aws-amplify/amplify-hosting

URL with Trailing Slash with Next.js returns 403 status code

Open
#3,373 5 comments 0 reactions 1 assignee Assigned to @Jay2113 View on GitHub
compute investigating question redirects
Dominant language
Dockerfile
Stars
481
Forks
123
PR merge metrics
No merged PRs in 30d

Description

### Before opening, please confirm:

- [X] I have checked to see if my question is addressed in the [FAQ](https://github.com/aws-amplify/amplify-hosting/blob/master/FAQ.md).
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-hosting/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-hosting/blob/master/CONTRIBUTING.md).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.

### App Id

d17g4lsg0ngzxg

### AWS Region

us-east-1

### Amplify Hosting feature

Not Applicable

### Describe the bug

I have deployed a simple Next.js SSG website with an index page and test page. Repository: `https://github.com/anatolzak/nextjs-trailing-slash`

Pages:
`https://main.d17g4lsg0ngzxg.amplifyapp.com`
`https://main.d17g4lsg0ngzxg.amplifyapp.com/test`

And I don't have any rewrites or redirects.

When going to `https://main.d17g4lsg0ngzxg.amplifyapp.com/test`, everything works correctly. But when going to the same url but with a trailing slash, I get a 403 page.

So apparently, trailing slashes don't work

### Expected behavior

URLs with a Trailing slash should redirect to their counterpart without a trailing slash which is the default behavior for Next.js apps as described here: https://nextjs.org/docs/api-reference/next.config.js/trailing-slash.

Or URLs with a trailing slash should at least not return 403 status code and instead just render the same page as without a trailing slash.

### Reproduction steps

1. Deploy a Next.js app
2. Delete any rewrites or redirects
3. Go to any page except the index page and add a trailing slash to the url, and you should get 403

### Build Settings

_No response_

### Log output

```
# Put your logs below this line

```

### Additional information

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.