drupal_goto() not remove url path of 404 page
Hope this will help you,

In Drupal 7 , you can check whether the page is 404 page or not. If it is a 404 page then change the drupal_goto $path parameter.


drupal_get_http_header : Gets the HTTP response headers for the current page.



  $status = drupal_get_http_header("status");
  $path = ($status == '404 Not Found'){
    //change the path from example.com/nopage/searchyour/trips to example.com/searchyour/trips
    drupal_goto('/searchyour/trips', array('query' => $query));  
  }else{
    drupal_goto('/searchyour/trips', array('query' => $query));
  }