How to make Drupal 6 search result URL use "-" instead of space? Example of Drupal 6 search result URL is like this:

http://www.site.com/search/node/Search for something


How to make Drupal 6 search result URL use - instead of space? (below is an example):

http://www.site.com/search/node/Search-for-something
You could add the functions custom_url_rewrite_inbound() and custom_url_rewrite_outbound() in the settings.php.

custom_url_rewrite_outbound() would rewrite the URLs which are output from any module, and custom_url_rewrite_inbound() would rewrite the URL being requested to Drupal.

This is the example code used in the documentation of custom_url_rewrite_outbound().

function custom_url_rewrite_outbound(&amp;$path, &amp;$options, $original_path) {
  global $user;

  // Change all 'node' to 'article'.
  if (preg_match('|^node(/.*)|', $path, $matches)) {
    $path = 'article' . $matches[1];
  }
  // Create a path called 'e' which lands the user on her profile edit page.
  if ($path == 'user/' . $user-&gt;uid . '/edit') {
    $path = 'e';
  }
}


In your case, the code could be something similar to the following one.

function custom_url_rewrite_outbound(&amp;$path, &amp;$options, $original_path) {
  if (preg_match('|^search(/[^/]+/(.+))|', $path, $matches)) {
    $path = 'search/' . $matches[1] . str_replace(' ', '-', $matches[2]);
  }
}


custom_url_rewrite_inbound() should do the exact opposite.
The code I wrote does not consider the case the - is included in the search string. The code should consider that case, for example adding another - where there is already one; when it does the opposite operation, the code should first replace a single - with a space, and then remove a - where there are more of those characters in row.