I have a catalog of products in one of my website, each year there are new products and some old products are unpublish (never deleted). Some websites put links to the products, so when a product is unpublish, all those referents links becomes invalid and are redirect to a 404 pages.
Now i don't want that, i want a custom redirection to parent category of the product. For that i catch the 404 event, and then i tough i could just make a dbquery on my node items to found the parent's category, and create a redirection.
I catch the 404 in the template.php file like that :
function myTheme_preprocess_node(&$variables) {
$node = $variables['node'];
if (!empty($node)) {
$headers = drupal_get_headers();
if (preg_match('@HTTP/1\.[01]\x20+404@', $headers)) {
//want to do my redirection here
}
}
but when i try to get my url, i get in fact the url of the 404 pages but in the url bar, it's still the product url.
So how can i get that url or simply the invalid nid?
$node->nid
is the invalid nid assuming all the rest of your code is valid. – Jimajamma Oct 17 '12 at 15:53