I am using Drupal 7 and my search functionality is not working properly.

When I click on search button without enter any keyword it redirects to home page with showing the message Please enter some keywords. and same thing happens when there is no result found for the respective search keyword.

So can anyone please guide me how can I redirect the empty search to search page?

Thanks in advance...

  • I had the same problem right after adding the search block to the front page. Clearing cashes solved the problem.
    – Jeroen
    Commented Jan 6, 2018 at 16:36

1 Answer 1


Something like this should work:

 * Implements template_preprocess_search_results.
function YOUR_THEME_preprocess_search_results(&$variables){
  $results = $variables['results'];
  if(count($results) == 0){

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.