-
-
Save nocodesupplyco/6b8477578e2c9971e009ac3ed388780d to your computer and use it in GitHub Desktop.
Bulk Delete 301 Redirects From Webflow
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const deleteRedirects = async (redirects) => { | |
const xsrfToken = document | |
.querySelector('meta[name="_csrf"]') | |
.getAttribute('content'); | |
const shortName = window.location.href.split('/')[5]; | |
for (const path of redirects) { | |
const bodyContent = JSON.stringify({ path }); | |
try { | |
await fetch( | |
`https://webflow.com/api/sites/${shortName}/redirect/delete`, | |
{ | |
headers: { | |
'content-type': 'application/json', | |
'x-xsrf-token': xsrfToken, | |
}, | |
body: bodyContent, | |
method: 'POST', | |
} | |
); | |
console.log(`Deleted redirect: ${path}`); | |
} catch (error) { | |
console.error(`Error deleting redirect: ${path}, ${error}`); | |
} | |
} | |
}; | |
const redirectsToDelete = ['/first-slug', '/second-slug']; | |
deleteRedirects(redirectsToDelete); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment