Last week on our blog, we discussed best practices for keywords to help improve your SEO and optimize your Drupal website. In this post, we’re going to dig deeper into one of the most important optimization strategies for SEO and search engine results page (SERP) performance -- friendly and descriptive URLs.
URLs help to describe a website or page to both visitors and search engines. Keeping them relevant, accurate, and concise is a key component to your content ranking well. Your URLs should be as descriptive as possible while also being brief -- for example, if your content is nested within several layers of navigation, then its URL should reflect this with folders and subfolders. The URLs of individual pages should also reflect its content, ideally the title so that a visitor who only sees the URL on a search results page can easily infer what to expect from the page.
Also remember to optimize your URLs -- avoid extraneous characters, using dashes, and include appropriate keywords.
When a new page or post is created in Drupal, the URL that it is assigned defaults to the dynamic, and search engine unfriendly, format of /?q=nodeID. For example, your About Us page would have a default URL such as http://www.yourdomain.com/?q=node/1.
To change your default to a cleaner URL, navigate to Admin → Configuration → Search and Metadata → Clean URLs and click on the checkbox to enable clean URLs. This removes the ?q= portion of the URL, resulting in a friendlier http://www.yourdomain.com/node/1.
Now that your URLs are friendlier, the next step is to make them descriptive as well. URL aliases replace the node ID with a slug, which you can manually update in URL path settings field at the bottom of your content template.
This will result in both a friendly and descriptive URL for your page, such as http://www.yourdomain.com/hello-i-am-an-alias. To add or manage alias paths, navigate to Admin → Configuration → Search and Metadata → URL Aliases.
Taking Your Friendly URLs to the Next Level
With the basics of your friendly URLs now set up, there are two other Drupal modules that will work together to add extended functionality to URL paths and aliases: Pathauto and Token. Pathauto aliases the path of a formed URL to the actual node in Drupal, and the pattern of text that forms the URL is assisted by token -- typically the title of the content page or article or from a number of variables.
This automates the manual process we described in the previous section, which is managed in the Drupal admin through the addition of a “Pattern” tab in the URL Aliases section and allows you to set default URLs for your content based on a pattern that you define.
This new tab allows you to configure each of your content types as well as taxonomies and user nodes. Adding a default path for all content types will apply it if any other content type is left undefined. Taxonomy tags and user account pages are separate nodes that are indexed by search engines and delivered in their results, so we recommend defining them as well.
By inserting or copying the replacement patterns, which are the tokens or variables, you can define the default patterns of your URLs but the default replacements will serve most user’s needs:
Finally, to ensure that your friendly URLs are automatically created, double-check that the “Generate automatic URL alias” option is checked in the URL path setting section at the bottom of your content template. Or, if you’d prefer, you can uncheck this option and manually enter a URL alias for that specific piece of content.
Finally, one word of caution about the automatic method: if you change the title of the content in the title field, the URL will also change. This will mean that the previous URL will result in a 404 error if it’s accessed.
There are two solutions to this: you can uncheck “Generate automatic URL alias” after you publish the content and before you change the title, or you can use the Redirect module. The module tracks all of the URL alias changes and redirects any attempts to access older URLs that have been changed and is a much safer solution that remembering to manually undo the automatic process.