Drupal 7 Pathauto Module
Share with Others
The Drupal 7 Pathauto module allows you to easily create patterns for the URL alias of any content you create on your Drupal 7 site. This is a module that I install on almost all my Drupal sites.
In this episode you will learn:
- How the Drupal 7 Pathauto module can automatically create URL aliases on your Drupal site based on a pattern
- How to bulk update or delete URL aliases
Hello there everyone and welcome to another Daily Dose of Drupal, this is Episode Number 71 today, as always I’m Shane, go ahead and follow me on Twitter if you haven’t already @smthomas3 and sign up for the codekarate.com newsletter and find me on Google +.
Today we’re going to be keeping it short and simple, the Path Auto Module. You most likely if you’ve around Drupal for very long you already know this module so you can probably skip this episode in all honesty but if you haven’t heard of this module it is one that you should probably be installing on most of your sites.
By default I pretty much installed this on every Drupal website I’ve built and it’s especially important if you have users who are going to be generating content like blog post or articles and they don’t necessarily know the ends of now with Search Engine Optimization and what it allows you to do is it allows you to automatically use a pattern to generate the URL Alias for a specific piece of content and it is extremely easy to configure so we’re going to hop right in and get started and be out of here in no time. I’ll go to the module’s page and show you that I do have it installed, I have this 7.x-1-2 version which is the current version and I’m going to go ahead and you can of course set the permissions, I’m just going to go to the configuration page.
The first tab you can open up here list all the aliases on the site. So as you can see they’re all defaulted to content/ something which is the default for any type of content. You can of course edit this if you wanted to change the alias so if you wanted to do something like that, change it from a really long URL to just a longer FAQ answer which was related to the FAQ Module a few days ago.
But what this allows you to is of course fine tune it and make changes, you can filter here, you can add an alias but we’re going to go to the Pattern. So this is where it gets a little more interesting.
This requires a token modules so you’re going to need to make sure that installed as well but it allows you setup this pattern using tokens. So for instance we’re going to look on the Content Path, that’s the important one, I do have … there would be one listed here for each different type of content on the site.
So I have Article Content Type, Basic Page Content Type, FAQ Content Type and so on and so forth. It all defaults back to this; the Default Pattern. So if there is something listed here when you create a piece of content it’s going to default to this. Let’s go ahead and change this; let’s change this to be Articles/ and you can of course come down here for the Replacement Patterns, you can use the current date for instance, let’s go ahead and say we want it to be … we could go ahead … we won’t use a in this instance, we’ll go ahead and use something else, you can have Node Author for instance so it could be articles/author/ and then we’ll go into node title.
So now instead of just contents/ the node title is going to be articles/author/node title. This could be useful if you have many different authors that are posting blog post and you want to separate it out a little bit or give you URL’s some structure and you can of course do this for all this different content types so you could have this faq/node title or anything else in here.
Whenever you want from the token list in this section and a lot of these breakdown and have a couple of different options within then so you can really look and see what’s available, you can easily just select it, click on the token down here and as you can see it drops it in. So that’s how that works, we’re going to go ahead and give it a try.
You can do this for taxonomy, paths, user paths and the FAQ Module has it so modules can build in their own sections in here but the content path is going to be the one you’re definitely going to look at and of course taxonomy might be important for you and users depending on your site.
So now that I save this I’m going to go ahead and create a piece of content; I’ll create an article, let’s give this s little bit of text and we’ll just go ahead and save it. The first thing to notice is now it’s … the URL up here is test4.codekarate.com/articles/shane which is the current user name and I’m logged in as test-path-article. So that’s all working great, it just sets what we would hope and then basically what it allows someone to do is even if they go in and they’re creating an article and they do not have access to this URL Path settings it’ll automatically generate that article.
One thing you’ll notice is this is an old article; it still has the old URL alias. I can click this checkbox to generate it automatic URL alias and save it and then we’ll go ahead and update it but what we really wanted to be able to do is we really want to be able to these in bulk.
So first we’ll check out the settings; I generally don’t ever change the settings here, they come with much pretty sensible defaults but you can have a look; here you change a separator, change the different alias links, it removes strings, common strings from the title if you’re using like a node title or something else, it’ll remove it from the path but you can also do this Bulk Update. So we can go ahead in Bulk Update any of these different types; content, taxonomy, user paths but before we do that we’re going to go ahead and go to Delete Aliases.
We’ll just go ahead and delete all the content aliases because most of these are articles and we’ll now do a bulk update on the content path. You can see it generate 15 URL aliases and now you’d notice I come back to content/testarticle-1 and it’s gone. That is important to note, you might want to be careful doing these Bulk Updates if you have a live site and a lot of content because the search engine will have a hard time finding those and you might have broken links so you may need to use other modules like the Redirect Module and you can look at some of these recommended modules here; with the redirection path, redirect modules depending on D6 or D7 but we’ll come back to the homepage you can see the articles of course are still there, if I hover over it and look down here at the URL at the bottom you can see that that one becomes article/chains/test-article1/article/chain/test-path-article.
So really easy, really basic, go ahead and give it a try if you’re not already using this. Like I said before it’s something that I use in almost every Drupal site I build especially if I’m going to have other people creating content that’s going to be … or that I want to be index on the search engines having a nice clean URL path definitely helps with not only allowing the user to see a little bit about what the page may be about but also helps the search engines better index your site. So go ahead and give a try and I will talk to you next time on the next episode of the Daily Dose of Drupal. Thanks for watching.