htaccess and Url rules - two questions


I have two questions for you about Url Rules or htaccess file.

Now I have:

            'baseUrl' => '/',

            'enablePrettyUrl' => true,

            'showScriptName' => false,

            'rules' => [

			'/' => 'site/index',

			'ad/<id:\d+>' => 'ad/view',


And it works, when I type ad/NUMBER it displayed correctly advertisement, but I would like to show it like this:


how to do it?

And second question:

How to set the Url Rules for specific id?

for example:

I have ad/show?category[id]=1

How to change it to display the name of the category depending on the number ?

ad/show?category[id]=1 ----> cars

ad/show?category[id]=2 ----> house


Question 1.

Just add one parameter

‘ad/<id:\d+>/<slug>’ => ‘ad/view’,

Your action can be still just

function actionView($id) {



But when you create url you can use ‘slug’ key

Question 2

Sorry, have not understood