Recently I was asked how to support a permalink to content on a Drupal website. This was a somewhat interesting request because I’m working on a site with hundreds of thousands of Nodes and ideally all content should be reachable from a permanent URL. This website is cited often on academic journals and other news sites. So I wanted to assure I understand the appropriate way to provide a permanent link on important content types. This blog post is part 1 of a 2 part series on Permalinks.
What is a Permalink?
A Permalink is a permanent url link to a specific web page. As I mentioned above the document site I’m building has 150,000+ documents and counting and so every document needs some sort of unique identifier. The simplest solution in Drupal for a permanent url is to use the system provided Node ID (NID) for drupal content and the canonical path for content in Drupal. That is ?q=node/NID if your webserver doesn’t support url redirects or /node/NID if it does.
Every piece of Content in Drupal is typically a Node. All nodes, by convention in drupal, are given a unique ID in the system, known as the Node ID and a path of the format /node/NID.
In order to not require creating random unique numbers to represent our content the simplest solution is to use this built-in constraint. Otherwise you need to use something like the Snowflake API from Facebook which generates unique IDs for content with simple guarentees.
Personally, I don’t like devulging information of the underlying system such as primary database table keys to the user, but oh well — without complicating the project further it’s simply the easiest path to take.
Implementing the Permalink within the HTML Source
A simple solution to this problem is to install the Metatag module for Drupal. The metatag module allows you to customize HTML typically found within the head element of an HTML page. The enduser may not be savvy enough to find this information but search engine bots are — which is great!
By simply installing the metatag module some sane defaults are given to make the shortlink into the Node ID we want:
By inspecting the page’s HTML source code we can see the shortcode in place:
So this is achieving the goal we want. The only side affect of this that we want to avoid is that now our content is accessible from the canonical url of /inst-it-workgroup/it-section-homepage and also /node/50001. This is bad for SEO and Search Engines.
Fortunately this has been thought up long ago by the creators of the Global Redirect module. This module looks to see if the incoming url is an alias and if it is redirects to the canonical (pretty) url, thus saving SEO rankings.
In Part 2 of this blog post we’ll be showing how to embed the shortlink as text into piece of Drupal content.
Looking for quality web hosting? Look no further than Arvixe Web Hosting!