Amazon web services 如何使用AWS Lambda&;删除.html扩展名;云锋 我的网站源代码存储在AWS S3中,我正在使用AWS Cloudfront交付我的内容 我想用AWSLamda@Edge从通过Cloudfront提供的所有web链接中删除.html扩展名 我需要的输出应该是www.example.com/foo而不是www.example.com/foo.html,或者example.com/foo1而不是example.com/foo1.html
请帮助我实现这一点,因为我无法找到明确的解决方案来使用。我已经提到了本文中提到的第3点:。但我不清楚我需要做什么 PFB lambda代码,如何修改-Amazon web services 如何使用AWS Lambda&;删除.html扩展名;云锋 我的网站源代码存储在AWS S3中,我正在使用AWS Cloudfront交付我的内容 我想用AWSLamda@Edge从通过Cloudfront提供的所有web链接中删除.html扩展名 我需要的输出应该是www.example.com/foo而不是www.example.com/foo.html,或者example.com/foo1而不是example.com/foo1.html,amazon-web-services,aws-lambda,amazon-cloudfront,aws-serverless,aws-lambda-edge,Amazon Web Services,Aws Lambda,Amazon Cloudfront,Aws Serverless,Aws Lambda Edge,请帮助我实现这一点,因为我无法找到明确的解决方案来使用。我已经提到了本文中提到的第3点:。但我不清楚我需要做什么 PFB lambda代码,如何修改- const config = { suffix: '.html', appendToDirs: 'index.html', removeTrailingSlash: false, }; const regexSuffixless = /\/[^/.]+$/; // e.g. "/some/page" but not "/
const config = {
suffix: '.html',
appendToDirs: 'index.html',
removeTrailingSlash: false,
};
const regexSuffixless = /\/[^/.]+$/; // e.g. "/some/page" but not "/", "/some/" or "/some.jpg"
const regexTrailingSlash = /.+\/$/; // e.g. "/some/" or "/some/page/" but not root "/"
exports.handler = function handler(event, context, callback) {
const { request } = event.Records[0].cf;
const { uri } = request;
const { suffix, appendToDirs, removeTrailingSlash } = config;
// Append ".html" to origin request
if (suffix && uri.match(regexSuffixless)) {
request.uri = uri + suffix;
callback(null, request);
return;
}
// Append "index.html" to origin request
if (appendToDirs && uri.match(regexTrailingSlash)) {
request.uri = uri + appendToDirs;
callback(null, request);
return;
}
// Redirect (301) non-root requests ending in "/" to URI without trailing slash
if (removeTrailingSlash && uri.match(/.+\/$/)) {
const response = {
// body: '',
// bodyEncoding: 'text',
headers: {
'location': [{
key: 'Location',
value: uri.slice(0, -1)
}]
},
status: '301',
statusDescription: 'Moved Permanently'
};
callback(null, response);
return;
}
// If nothing matches, return request unchanged
callback(null, request);
};
请帮助我从我的网站中删除.html扩展名,以及我需要在AWS Lambda中粘贴哪些更新的代码
提前谢谢 检查可能会帮助您-我需要使用AWSLamda@Edge若要删除.html扩展名,请检查此项-请提供我可用于此目的的lamda代码,并在此处共享lambda代码。