I'm trying to create an alias www.mysite.com/cars to show all search results for the following apache solr search www.mysite.com/search/apachesolr_search/?filters=type%3Acars%20tid%3A10%....

The results in a page where solr suggests an alternative version of the part after the question mark.

I found some threads that discuss the problem of using query arguments in url alias (in general) and wanted to doublecheck if it's really impossible to assign a clean url alias to a specific apache solr search?

Comments

ThePickwickProject’s picture

I got confirmation that at the moment of writing it is not possible to create a clean url for a link that contains a "?" with parameters. A workaround is use of the path redirect module.

Tomefa’s picture

My solution for this was to put some code in settings.php

function custom_url_rewrite_outbound(&$path, &$options, $original_path) {
  // Filter to get only the apache solr links with filters so it doesn't launch it for every link of our website
  if ($path == 'search/apachesolr_search/' && strpos($options['query'], 'filters') !== FALSE) {
    $new_path = $path.'?'.urldecode($options['query']);
    // See if we have a url_alias for our new path
    $sql = 'SELECT dst FROM {url_alias} WHERE src="%s"';
    $row = db_result(db_query($sql, $new_path));
    // If there is a dst url_alia, we change the path to it and erase the query
    if ($row) {
      $path = $row;
      $options['query'] = '';
    }
  }
}

function custom_url_rewrite_inbound(&$result, $path, $path_language) {
  // See if we have a url_alias for our new path
  $sql = 'SELECT src FROM {url_alias} WHERE dst="%s"';
  $row = db_result(db_query($sql, $path));
  if ($row) {
    // We found a source path
    $parts = preg_split('/[\?\&]/', $row);
    if (count($parts) > 1) {
      $result = array_shift($parts);
      // That's important because on my website, it doesn't work with the / at the end of result
      if ($result[strlen($result) - 1] == '/') {
        $result = substr($result, 0, strlen($result) - 1);
      }
      // Create the $_GET with the filter
      foreach ($parts as $part) {
        list($key, $value) = explode('=', $part);
        $_GET[$key] = $value;
        // Add this because the pager use the $_REQUEST variable to be set
        $_REQUEST[$key] = $value;
      }
    }
  }
}

And then when you create a menu entry, you put the link to apache solr : search/apachesolr_search/?filters=tid:13

And create a url alias for search/apachesolr_search/?filters=tid:13 like products/tv.html

arekanderu’s picture

The above solution didn't work for me in drupal 6.20, I am still getting error when i try to create the menu item

"The path '/apachesolr_search/' is either invalid or you do not have access to it."

This is beyond frustrating.

qasimzee’s picture

I am facing exactly same issue, you got some solution?

--
Qasim Zeeshan
http://qasimzeeshan.com