Configuring UrlManager for OpenSearch controller

I am trying to add OpenSearch functionality to my application and have trouble configuring the UrlManager to route a search request to the right controller and method. The search works great if there are no white space in the search words. Whenever someone searches for more than one word, the UrlManager cannot find the controller and method to handle the search.

The url in the search.xml file that triggers the search is like this:


<Url type="text/html" template="[pathToMyApp]/application/index.php/query/{searchTerms}"/>

And my UrlManager is configured like this:




  'urlManager' => array(

    'urlFormat' => 'path',

    'rules' => array(

       '<_c:(name|tag)>s/*' => '<_c>/index',

       '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',

       'query/suggest/<needle:\w+>'=>'query/suggest',  // used to route OpenSearch JSON suggestions - works

       'query/findbox'=>'query/findbox',  // routes search queries from a form in the application - works

       'query/<needle:\w+>'=>'query/index', // works only for search strings with no white space

    ),

    'showScriptName' => true,

  ),



Any help will be appreciated

I got some help at stackoverflow.com [forum won’t let me post the url here].

Basically, my regex was too tight, so changing the rule fixed it:


'query/<needle:[\w, ]+>'=>'query/index',