Global Redirect module after spaces / purl install does not

Posted: 2013-01-15 07:54:00

Sometime when using spaces and purl there are Pages Not Found even though they are there. This is one reason. There is a space that purl is looking for a url starting with eg test. Some day you make a node test/testmore and decide later to use drupal's redirect to save the url test/testmore and delete the node (or unpublish it) But since spaces and purl is keeping an eye on test it will not work. Purl will strip the redirect of the test part $_REQUEST['q'] making it so this would fail since it no longer is in this space. This minor hook_init can do a double check.

function path_redirect_extra_init() {
  //Check if empty page
  $status = menu_get_item($_GET['q']);
  //print_r('Menu get item ' . $status);
  if(empty($status)) {
    //do one more check if this can be redirects
    if(isset($_REQUEST['q'])) {
      $original_request = check_plain($_REQUEST['q']);
      $result = db_query("SELECT redirect FROM path_redirect WHERE source LIKE \"%s\"", $original_request);
      while ($row = db_fetch_array($result)) {
        drupal_goto($row['redirect'], $query = NULL, $fragment = NULL, $http_response_code = 301);
      }
    }
  } 
}

The http://drupal.org/project/fast_404 module used hook_boot which may have worked as well. Also this is d6 and d7 has the hook_url_inbound_alter and hook_url_outbound_alter whereas d6 closest option to these is custom_url_rewrite_inbound


Tags:

bug