- Исходный код моего сайта хранится в AWS S3, и я использую AWS Cloudfront для доставки своего контента.
- Я хочу использовать AWS Lamda@Edge для удалите расширение. html из всех веб-ссылок, которые обслуживаются через Cloudfront.
- Требуется вывод www.example.com/foo вместо www.example.com/foo.html или example.com/foo1 вместо example.com/foo1.html.
Пожалуйста, помогите мне реализовать это, поскольку я не могу найти четкое решение для использования. Я упомянул пункт 3, упомянутый в этой статье: https://forums.aws.amazon.com/thread.jspa?messageID=796961&tstart=0. Но не ясно, что мне нужно сделать.
PFB лямбда-код, как я могу его изменить -
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 лямбду Заранее спасибо !!