Created
September 26, 2018 14:56
-
-
Save pesterhazy/05639a992fdaa965464e7ce680832712 to your computer and use it in GitHub Desktop.
Lambda@Edge trigger: simple URL rewriting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
// Lambda@Edge trigger to serve index.html when the | |
// user requests /app/*; use in Cloudfront as a viewer-request | |
// event | |
exports.handler = (event, context, callback) => { | |
const request = event.Records[0].cf.request; | |
if (/^\/app($|\/)/.test(request.uri) || request.uri == "/") { | |
request.uri = "index.html"; | |
} | |
callback(null, request); | |
}; |
As far as I know, you can only rewrite urls on the same host. You can’t
pick a different origin. Not 100% sure though
You can return a 30x redirect though
…On Mon 2. Mar 2020 at 17:22, Christian Dechery ***@***.***> wrote:
Would a code like this one work to rewrite a URL that is served by another
domain?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://gist.github.com/05639a992fdaa965464e7ce680832712?email_source=notifications&email_token=AAAZ6WAYV4KH4E6WHNP35I3RFPMLFA5CNFSM4K7XXO22YY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAGDC5M#gistcomment-3196374>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAZ6WCZPBX2JB5NA33T3HDRFPMLFANCNFSM4K7XXO2Q>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Would a code like this one work to rewrite a URL that is served by another domain?