How can I convert these URL to SEO friendly URL I tried Url manager in yii but didn't get the proper result is there any good tutorial regarding url manager
http://localhost/nbnd/search/city?city=new+york
http://localhost/nbnd/search/manualsearch?tosearch=Hotel+%26+Restaurants+&city=New+york&yt0=Search&searchtype=
I tried to the following setting in url manager
'<controller:\w+>/<action:\w+>/<city:\d>'=>'<controller>/<action>',
which works with url http://localhost/nbnd/search/city/city/Delhi
I wish to reduce this url to http://localhost/nbnd/search/city/Delhi
and the link I generating in my view is <?php echo CHtml::link(CHtml::encode($data->city), array('/search/city', 'city'=>$data->city)); ?>
This generates link as http://localhost/nbnd/search/city?city=Delhi
How can I convert that link to like http://localhost/nbnd/search/city/Delhi
The rule should be (to remove the extra city, which is the GET parameter name):
So the rule should be able to match the parameter name, incase you had foo/Delhi, you'd use
<foo:\w+>
.And to remove the
?
useappendParams
ofCUrlManager
, (in yoururlManager
config):When
appendParams
Update: Incase you have more than one parameter being passed to the action i.e:
Use a
/*
at the end of the rule:To get urls of form:
In Yii we can create urls dynamically For eg.
we would obtain the following URL:
To change the URL format, we should configure the urlManager application component so that
createUrl
can automatically switch to the new format and the application can properly understand the new URLs:WE will obtain this
You can refer this link for user friendly urls in yii http://www.yiiframework.com/doc/guide/1.1/en/topics.url