6

I am using Pathauto. When I deleted a piece of content, I was surprised to find that its url alias was still mapped to the now-nonexistent content (node/xxx).

How can I have this alias and System name mapping removed automatically when the node is deleted?

Edit: I want to keep the Update action set to "Do nothing. Leave the old alias intact.", because I don't want paths to change when nodes are adjusted. However, it doesn't make sense to keep a path around if the node was deleted completely. Can I have both options somehow?

3 Answers 3

8

You can use hook_node_delete:

function hook_node_delete($node){
    // Delete alias.
    $path = path_load(
      array('source' => 'node/'.$node->nid)
    );

    path_delete($path['pid']);
}
3

You can update aliases here, or on the node

/admin/config/search/path

or bulk update a whole bunch here

/admin/config/search/path/update_bulk

based on an alias pattern change set here

/admin/config/search/path/patterns

I imagine the reason it "Seems" like an alias didn't delete is because it have forwarding to another alias in a sort of chain. Drupal does clean up alaises on content delete, ou can do a simple test and see it happen. But if you have alaises chained it only seems to delete the final alais and leave the others. I think if you update you "update actions" you can minimize the number of extra alaises created.

Go here and find the section called "Update action" /admin/config/search/path/settings

You have three choices of what to do when an alais changes

  • Do nothing. Leave the old alias intact.
  • Create a new alias. Leave the existing alias functioning.
  • Create a new alias. Delete the old alias.

Also based on there advice "Considering installing the Redirect module to get redirects when your aliases change."

I hope this helps ans isn't off base but I faced similar issue on a site with 500k items and the clean up was a serious issue. Best of luck!

1
  • Lots of info in this answer, but I've looked through all those options. Still don't see anything that answers the question. Feb 3, 2015 at 0:27
1

You can update the path aliases here in the Admin > Config menu: admin/config/search/path/update_bulk

1
  • 1
    This neither removes the mapping nor is automatic... Jan 27, 2015 at 19:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.