Wednesday, July 31, 2024

Fix broken, deleted and damaged links via Cloudflare

Broken, Deleted and Damaged Links Repair via Cloudflare
Broken links are broken links, meaning that the link on the target blog no longer exists (404 error). Either a link on the blog itself, or external (outside the blog)

The impact of broken links on SEO

Of course it will be very influential and very bad. As a blogger, you of course not only face the device, but also the user (user experience). What happens when some users click on a link and the link is not there. It is unlikely that they will return to our blog.

Reasons for broken links

Among the reasons for broken links are:
  1. Writing the content incorrectly / typo
  2. Changing the permalink
  3. Deleting the post / file URL
  4. Changing the redirection to self-hosting
  5. Replacing the domain or custom domain / domain
  6. Changing the dll ...
A custom domain is what happens most often on Blogger. When creating a custom domain, many links use the unchanged blogspot domain, which leads to redirects like this

How to check for broken links

To check if there is a broken link on our blog or not, we can use the online tool brokenlinkcheck.com

Solutions

The best solution is of course to fix the link, but when there are too many links that take time to edit, we can use Cloudflare first

Using Cloudflare for broken links

There are several steps to use Cloudflare (of course the blog must already be using Cloudflare DNS)
1. Create Agent > Create Agent, copy the script (edit the code with your information, for example, I have a contact us page with a redirect problem, so I replaced the old link to the broken page with the new and working link to the page)

const OLD_URL = "https://www.en.naljaede.com/p/contact.html"

const NEW_URL = "https://www.en.naljaede.com/p/post-contact-form.html"

async function handleRequest(req) {
  const res = await fetch(req)
  return rewriter.transform(res)
}

class AttributeRewriter {
  constructor(attributeName) {
    this.attributeName = attributeName
  }
  element(element) {
    const attribute = element.getAttribute(this.attributeName)
    if (attribute) {
      element.setAttribute(
        this.attributeName,
        attribute.replace(OLD_URL, NEW_URL),
      )
    }
  }
}

const rewriter = new HTMLRewriter()
  .on("a", new AttributeRewriter("href"))

addEventListener("fetch", event => {
  event.respondWith(handleRequest(event.request))
})

2. Then rename it for example 301-mui
3. Create Route > Add Route

Use *www.en.
naljaede.com/* replace with your domain name, the created operator for example 301-mui

Conclusion

You can attribute several reasons for the problems to broken or broken links or those that contain redirects, so apply the explanation above and you will see very good results

Show Comments