If you've deleted or renamed a page on your Durable site, it's important to set up a 301 redirect. This helps guide visitors to a working page instead of landing on a 404 error, and ensures search engines update their index with the new URL.
Follow the steps below to create a 301 redirect on your site:
Go to Website > Settings.
Scroll down to the Custom Code section and paste the applicable codes into the header section.
Codes:
Single page<script>
var currentPath = window.location.pathname;
var pathToRedirect = "/page1";
if (currentPath.includes(pathToRedirect)) {
window.location.href = "/";
}
</script>Multiple page
<script>
const currentPath = window.location.pathname;
const oldPaths = ["/old-path1", "/old-path2", "/old-path3"];
if (oldPaths.some(path => currentPath.includes(path))) {
// Redirect to the homepage
window.location.href = "/";
}
</script>Multiple sending to different pages
<script>
const currentPath = window.location.pathname;
const redirects = [
{ oldPath: '/old-path1', newPath: '/' },
{ oldPath: '/old-path2', newPath: '/services' },
{ oldPath: '/old-path3', newPath: '/' }
];
redirects.forEach(({oldPath, newPath}) => {
if(currentPath.includes(oldPath)) {
window.location.href = newPath;
}
});
</script>Click Save.
If you need help managing your redirects or have questions about setting up your site, our team is here to help. Reach out anytime and we’ll be happy to assist you.