Skip to content

Commit

Permalink
Merge pull request #27 from azachwill/devcommit30
Browse files Browse the repository at this point in the history
devcommit30
  • Loading branch information
awilliams1275 authored Aug 19, 2024
2 parents 7d61191 + a88f7e9 commit 18060e8
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions netlify/edge-functions/redirect_index.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
export default async (request, context) => {
const url = new URL(request.url);
// Check if the URL path starts with /py and ends with a index.html
if (url.pathname.startsWith('/py/') && url.pathname.endsWith('index.html')) {
// Remove the trailing slash and add .html extension
const newPathname = url.pathname.slice(0, -1) + '/';
const newUrl = `${url.origin}${newPathname}`;

// Perform a 301 redirect
return new Response(null, {
status: 301,
headers: {
'Location': newUrl,
},
});
}
// If the URL does not match the criteria, proceed with the request as usual
return context.next();
};
export const config = {
path: '/py/*',
};

const url = new URL(request.url);
// Check if the URL path starts with /py and ends with a index.html
if (url.pathname.startsWith('/py/') && url.pathname.endsWith('index.html')) {
// Remove the trailing slash and add .html extension
const newPathname = url.pathname.split("index.html");
const newUrl = `${url.origin}${newPathname[0]}`;

// Perform a 301 redirect
return new Response(null, {
status: 301,
headers: {
'Location': newUrl,
},
});
}
// If the URL does not match the criteria, proceed with the request as usual
return context.next();
};
export const config = {
path: '/py/*',
};

0 comments on commit 18060e8

Please sign in to comment.