drupal_goto() not remove url path of 404 page I have a search form which returns to search page.

drupal_goto('/searchyour/trips', array('query' =&gt; $query));


this is work fine if a user in active page. search url will replace as eg: example.com/searchyour/trips

But if user in 404 page (example.com/nopage) and click search, search url will set to example.com/nopage/searchyour/trips I want to change this to example.com/searchyour/trips.

I'm new to drupal. Help me to solve this. :-)
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));
  }