Search code examples
amazon-web-servicesamazon-cloudfront

How to get the requested path on custom error page with cloudfront


I'm using a cloudfront distribution with a custom origin for error processing, well I need to know how to get the requested path in my error page. when "foo/file.htm" is requested a 404 Not Found Error is catched and the "error404.php" page is called in my server, well, I need to know the path that rises the error for building the response page and write "the file 'foo/file.htm' is not found" or something like that.


Solution

  • I think that would be a Dynamic Web Application's WebPage which you need to link it with the Error Page.

    In the Dynamic Web Application's webpage you need to get the query path from the domain of the incoming request and return back a new dynamic response back.

    The extra care you need to take from your side is that, CloudFront may cache the page; so ensure you set the cache expiry settings appropriately.

    Example :

    You get a request foo.html which not is your distribution, the CloudFront will talk to your origin server and get the new dynamic page like [ Sorry you have reached the wrong Page - foo.html ].

    The next time similarly when you get a request for bar.html which also not in your distribution, ensure the CloudFront talk to your origin server again and get the new page, if not even for the current request you might get the old error message [ Sorry you have reached the wrong Page - foo.html ] instead of the bar.html