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):

  • 1
    When someone makes a search query with a dash in it, how should it be represented in the url?
    – Greg
    Mar 26, 2011 at 17:20

2 Answers 2


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.


If you have installed pathauto module then Check admin/build/path/settings this setting.

  • Not sure how this would change the search URLs. Can you eloborate?
    – mpdonadio
    Feb 7, 2013 at 16:00

Your Answer

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