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(&$path, &$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->uid . '/edit') {
$path = 'e';
}
}
In your case, the code could be something similar to the following one.
function custom_url_rewrite_outbound(&$path, &$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.