Bulk Update Redirects After Changing URL Pattern in Drupal

Posted on August 15, 2015 - 2 Minute Read

I recently worked on a project where the site's URL structure was going to change. This is easy to do with Pathauto, but I wanted to ensure that the old URLs would redirect to the new URLs since this would affect hundred of nodes.

If you have Redirect enabled and you manually update a node's URL, the module will automatically create a redirect from the old URL to the new URL. However, since I would be updating hundred of nodes I needed an automated process. Below are the steps I took to bulk update redirects after changing a URL pattern.

  1. First, update your URL pattern by going to admin/config/search/path/patterns. In my case, I updated the patten for Articles. I changed it from news/[node:title] to blog/[node:title].

Screen Shot 2015 08 15 at 8 21 58 AM

Screen Shot 2015 08 15 at 8 23 46 AM

Screen Shot 2015 08 15 at 8 24 53 AM

  1. After updating the URL pattern, you do NOT need to delete all aliases, or run a bulk update under the Search and metadata configuration page. This will not create the redirects.
  2. Instead we want to create a new view to run a bulk operation. Create a view with a table display by going to admin/structure/views/add. Make sure to limit it to the content types(s) affected.

Screen Shot 2015 08 15 at 8 27 37 AM

  1. Add a field of Bulk operations: Content

Screen Shot 2015 08 15 at 8 28 25 AM

  1. Under Selected Bulk Operations select Update node alias.

Screen Shot 2015 08 15 at 9 23 04 PM

  1. Save the view and go the the page you just created to run the operation.

Screen Shot 2015 08 15 at 8 31 23 AM

  1. After running the bulk operation, navigate to an affected node and scroll to the bottom of the edit screen. You will see a redirect has been added. You can also test this by navigating to the original path and making sure it redirects to the new path instead of creating a 404 error.

Screen Shot 2015 08 15 at 8 34 43 AM

Categorized In:Tagged In: