How to deal with deleted posts: Returning 410 status and preventing path re-use For my jobs site, I want to return 410 status for those jobs which expire or are removed permanently. How can I do it so that 410 instead of 404 is returned for say job related node types( they'll be unpublished first and later deleted permanently I guess I should return 404 for unpublished then 410 when deleted)?

Secondly in case it really works out to use 410 for such pages but later new job pages may be published by Path Auto which could assign the very same url's based on title name for which 410 was returned once. I understand if a url comes back after 410 it will be permanently ignore by Google. So I guess I'd need that Path Auto always generate a non-duplicated (deleted) url. So solve this I'd need to tag an always increasing number with the url or adds jobs in url directories based on dates like xyz.com/oct/job1.... So I'd need to take care of this too if I'm able to return 410 for such page.
Pathauto will not duplicate paths. If your Pathauto URL pattern results in the path 'oct/job1' and that path already exists, Pathauto will add an integer to the end of the alias, incrementing it for every new 'identical' path. IE, you'll end up with these paths:

oct/job1
oct/job1-0
oct/job1-1
oct/job1-2
oct/job1-3


... etc.

So what you need to do is:


Implement hook_menu() to create a custom page callback that will map to a function which will return the 410 HTTP code.
Create the callback function for the path you created in hook_menu()
Implement hook_node_delete() and look at the type of the node being deleted; if the type matches the content type you're working with, run a query to update the url_alias database table, changing the 'source' of the records relating to your node from the 'node/##' value to the menu callback you created in step 1. This will prevent Pathauto from deleting the aliases, and will instead map them to your function which will return the 410 HTTP code.


One thing to keep in mind is that the module in which you implement this custom functionality needs to fire before Pathauto, so you may need to alter your module's 'weight' value in the system database table.