wolvorinePk
wolvorinePk

Reputation: 1790

adjust custom url using url manager yii php

i have url like

localhost/abc.com/info/c/q/Best%20Men

here info is the controller and c is action and q is query id.

i want to re write these url dynamically by removing c/q/ and using non space url. For instance like this

localhost/abc.com/info/Best_Men

is it possible using urmanager???

i tried this code but it didnt work

'info/c/<q:\d+>'=>'info/<q:\d+>',

[AFTER EDIT]

My config contained this

'urlManager'=>array(

    'urlFormat'=>'path',
'showScriptName'=>false,
 'caseSensitive'=>false,
    'urlSuffix'=>'.html',    

        'urlFormat'=>'path',
        'rules'=>array(

            'info/<q:\w+>' => 'info/c'

                ),
    ),

For more explaination here is what are my urls

http://localhost/abc.com/mycontroller/myactionsearch?q=Best

it returns me lists of searched items and on clicking any link it opens for e.g. clicking best men open this below link

http://localhost/abc.com/mycontroller/myactionItem/q/Best%20Men

so actually i have two different actions within same controller and now i want to make it run like

http://localhost/abc.com/mycontroller/Best%20Men

or

http://localhost/abc.com/mycontroller/myactionItem/Best%20Men

but it gives page not found error using above config

Upvotes: 0

Views: 631

Answers (1)

Jon
Jon

Reputation: 437734

That route is wrong for several reasons:

  • it does not match the specific query (\d means "digit", so it won't match "Best_Men")
  • it does not forward to a valid controller action
  • the pair of values should be switched around

Instead of this you want something more similar to

'info/<q:\w+>' => 'info/c'

Upvotes: 1

Related Questions