API GW Permanent 308 redirects

0

I've deployed my NextJS app in ECS via CDK. The basePath of my application is let's say '/abc'. I was able to access the server via API gateway without any issues.

Recently, I've added a configuration in NextJS - trailingSlash: true, which basically redirects any path without a trailing slash to a path ending with trailing slash. I need this for SEO purposes.

After I've made this change, when I deploy my server using a new docker image created, when I access the server via APIGW, I get a 308 permanent redirect issue and the page does not load. This is the behaviour -

  • When I hit the path '/abc', I initially get redirected to '/abc/' and then get continuously redirected to '/abc/' itself, hence a permanent redirect.
  • When I hit the path '/abc/' directly, I get continuously redirected to '/abc/' itself, hence a permanent redirect.

Now when I try and access the server via the network load balancer, everything works as expected -

  • When I hit the path '/abc', I initially get redirected to '/abc/' and then get a 200 response from the server
  • When I hit the path '/abc/' directly, I get a 200 response from the server

Why is this happening? Is there a configuration that I would need to change? I can provide additional information as needed.(Please consider that I'm an AWS beginner). Thank you

1개 답변
0

First, I would suggest to enable Execution Logs on the API and see the messages. Maybe it will give you a clue.

I tried it an it seems API Gateway strips the trailing / and therefore the backend always receives the URL without the trailing / and redirects again. You will be able to see that in the logs and probably also in your backend logs.

Are you using caching in API Gateway? If you are, it may be that API Gateway ignore the trailing / when it looks for a hit, so all requests to /abc and /abc/ are considered the same and GW returns the cached redirect response. (this is just a guess).

profile pictureAWS
전문가
Uri
답변함 3달 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠