How to Prevent Broken Links in Drupal

Have you ever experienced a broken page link or broken image display on your Drupal website?

Reduce the number of broken urls and image references by following this Drupal tip. You’ll experience fewer broken links and prevent these issues from happening in the future.

What is a broken link?

A broken link is among the worst actions a user can experience on a website, just shy of the white screen of death. A potential constituent clicks a link on your site and it takes them to an error page, or worse, to a generic error message. It interrupts their flow through the website and can cause them to completely abandon the website. At the very least, make sure you have a helpful 404 error page. This is the page a user sees if they visit a broken link or visit an incorrect url in their browser on your website.

How do links become broken?

So you remember creating this link a couple years back, or at least remember using this link a while ago and it worked fine. So why is it broken NOW? A few of the most common reasons are:

  • The page has been unpublished
  • The page exists, but the url has changed
  • The page has been deleted

If the page has been unpublished or deleted, you can either publish the page, recreate a new page, or update your link. Make sure to follow these next steps below for updating your link.

How to correctly add links within your main Drupal website content areas.

Using CKEditor WYSIWYG

  1. Highlight the text you want to link to and click the link icon
  2. Find the node id of the page you want to link to
    You can find the node id by editing the node of the page you want to link to and look in your browser url bar for the id number. For example, if the url bar contains .../node/813/edit... the node id is 813.
  3. Enter a relative url using the node id
    For example you would enter: /node/813.It is important that you use a relative url and not an absolute url. A relative url omits your domain address and starts with a forward slash. An absolute url contains the full page url, including https and your domain name. You should ONLY use absolute urls for external links. We suggest you configure external links to open in a new window.

Using node ids for page links protects your links from future changes.

For example, if you link to a vanity url such as “/my-vanity-url” then decide to change the url of that page to “/my-NEW-vanity-url”, you will experience a broken link. However, if you link to the node id url “/node/123”, your page links will not break and always redirect to the correct page url version.

Hint: a similar concept applies to your image urls. Always make sure to use relative urls when you embed images into your page content.

404 “missing” page errors are inevitable, but using these best practices for adding links in Drupal will minimize those errors. Good luck!

Related Blog Posts



Technologies for Nonprofits