How to redirect all 404s to the same path on a different server
-
16-10-2019 - |
Question
I want to redirect all 404 errors on my site to the same path on a different server.
For example:
http://drupal.example.com/url/not/in/drupal should be redirected to http://othersite.example.com/url/not/in/drupal
The sites are not on the same server and the other site is not running Drupal.
I know I can use the redirect module to redirect specific URLs but I don't have a complete list of the URLs on the other site so building the list is not practical.
Suggestions for modules or pointers to the appropriate hooks if I want to write my own module would be appreciated.
Solution
Here is small trick:
Enable module PHP Filter, add PHP filter to administrator
Create a node can use php filter, add code: (We are using header here, not use drupal_goto because handle 404 workfollow of Drupal will redirect to the node first.
<?php
$url = drupal_get_destination();
header('Location: http://other.example.com/' . $url['destination']);
drupal_exit();
?>
Config Drupal using 404 page is the node you was create.