使用AWS Lambda重写URL路径

时间:2019-12-03 22:17:55

标签: python aws-lambda amazon-cloudfront

我正在尝试使用Lamdba @ Edge重写下一个URL路径:

https://example.com/app OR https://example.com/app/ TO https://example.com/app/index.html
https://example.com/app/#/test123 TO https://example.com/app/index.html#/test123

使用官方文档,我编写了以下Python Lambda函数,但不确定哪里出错了。

def lambda_handler(event, context):
    request = event['Records'][0]['cf']['request']
    if request in ('https://example.com/app', 'https://example.com/app/'):
        request = "https://example.com/app/index.html"
    else:
        request = request.replace("/#/","/index.html#/")
    return request

0 个答案:

没有答案