6

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.

  • 2
    I can't understand what the second question is even asking. Please break this into two questions, and clarify the second one so it can be answered. – beth Jan 24 '13 at 19:26
  • I've made some correction. It isn't a question but more of problem to resolve. – AgA Jan 25 '13 at 6:42
  • 1
    Add [node:nid] as part of the pathauto alias and you have unique URLs for each job node. I don't see the importance of returning "410 Gone" though. Either make a custom 404 page or redirect to the job landing page or a page with similar jobs with a custom message that the specific job is no longer available. – enzipher Jan 30 '13 at 0:53
  • 1
    @enzipher - too many 404's shows poor management of site as per Google( I remember having read such literature) – AgA Mar 4 '13 at 5:36
2

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:

  1. Implement hook_menu() to create a custom page callback that will map to a function which will return the 410 HTTP code.
  2. Create the callback function for the path you created in hook_menu()
  3. 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.

  • Thanks Yuriy. Do you have any reference which I can look into ? Will deleting nodes later give any problem? – AgA Mar 3 '13 at 14:25
  • References for anything specific? Examples of the hook implementations can be found on the Drupal API (api.drupal.org). I'm not sure what you mean about deleting nodes 'later'. The way the flow I described would work is: 1). Your module's hook_node_delete() is executed and you update the path in the url_aliases table. 2) Other modules' hook_node_delete() are executed, and pathauto's own version doesn't find any matching records (since you've changed them) and it doesn't do anything. 3) Drupal core deletes the actual node record. – Yuriy Babenko Mar 4 '13 at 18:27
0

i would add a special flag (boolean via FieldUI) like deleted on that content type, then in the preprocess function for that content type, make an drupal_add_http_header, like if(DELETED) { drupal_add_http_header('status', 410); exit; }

  • But I want that page to be actually deleted. But if it is deleted then Pathauto could create the same url again later but in this case this new url will be permanently ignored by Google since it had retured 410 initially. – AgA Mar 3 '13 at 13:42
  • 1
    if you flag it as ignored, then even pathauto won't create the same uri again, as the page is still published. so a new page having the same title will automagically have a different uri. pathauto adds numbers. – rémy Mar 3 '13 at 16:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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