Post Title In Url Seo Friendly

Hi All,

I’m not a SEO expert, I have read that having is better than having

First of all… is that true? or it really doesn’t matter?

And how to achieve that? Because I always get the title like this title+post+testing-1, I have tried several options but any of them work.

URL Manager




I have read this wiki used for action controllers, do I have to do something similar?

Thanks in advance!

\d+ is for digits only. Use somehting like [\w\-]+ instead.

Thanks once again ORey for your response in one of my topic.

I have tried your tip but it doesn’t work as expected:




I have played with it, trying other options, but I always get the title separated with + sign

Any other tip is more than welcome, where I could search to find example rules or something like this?


ok, there are two parts actually:

  1. creating the URL

  2. parsing the URL.

Second part is already covered by your url rule. Now all urls that satisfy this regexp will be passed to blog/post/view.

Now the first part. Show me how you create your urls.

Speaking about the plus sign, it’s the usual behaviour of url_encode() used by UrlManager.

You can override this in child classes.

Either investigate the code by yourself (it can be easily found), or wait till tomorrow, I can find this place for you.

I mean, if you do something like this

createUrl('/blog/post/view', array('title' => 'Nice title with spaces'))

the result will be something like


It can be changed by many ways, including:

  1. creating a slug for every post (kind of ID but text, ‘nice-title-with-spaces’)

  2. overriding default urlmanager

and so on.

I’m not an expert also, but my SEO guys always want text instead of IDs. This freaks me out :)

I have a method on post model:

public function getUrl()


		return Yii::app()->createUrl('blog/post/view', array(





So I always call to this function, the URL result looks like this right now: ‘

Thanks ORey, I will try some other things, but if you find some other hint, please let me know, so much appreciate.

IMHO, the simplest solution is to change


to something like


or, better, create a getter in your model, like

public function getSlug()


    return some_function($this->title);


then you will be able to use

return Yii::app()->createUrl('blog/post/view', array(




some_function() should change all the spaces and other unwanted characters to ‘-’.

I was thinking in something similar, I have created a getter and used str_replace, works like a charm! thanks once again ORey!