Skip to content

Commit

Permalink
Merge pull request #25 from azachwill/devcommit28
Browse files Browse the repository at this point in the history
devcommit28
  • Loading branch information
awilliams1275 authored Aug 19, 2024
2 parents d24d419 + 098c586 commit 74c4ee6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netlify/edge-functions/redirect_article.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export default async (request, context) => {
if (url.pathname.startsWith('/py/docs') && url.pathname.endsWith('/')) {
// Remove the trailing slash and add .html extension
const newPathname = url.pathname.slice(0, -1) + '.html';
const newUrl = `${url.origin}${newPathname}${url.search}`;
const newUrl = `${url.origin}${newPathname}`;

// Perform a 301 redirect
return new Response(null, {
Expand Down
23 changes: 23 additions & 0 deletions netlify/edge-functions/redirect_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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/*',
};

0 comments on commit 74c4ee6

Please sign in to comment.