How to create SEO friendly URLs with editable post "slugs"?

Hi all!

What would be the best way to create WordPress like functionality to a Model?

So, instead of "www.domain.com/blog/123/link+to+page", I would like to have URL like this: "www.domain.com/blog/link+to+page" with option to modify that URL "slug" later.

Should I add unique column called "slug" to all my tables that needs this feature? How to handle URLs after I change the name of the slug?

Custom URL Rule Classes?

Sluggable Behaviour?

I know many have done something similar, so please tell your opinions/solutions.

Hi

under config/main.php

in this urlManager’=>array() add ‘showScriptName’=>false, than removed script name if you want to change name based on read from table and something else add ‘rules’=>include(‘route.php’),and make same file under config folder. it is look live below

return array(

'/'=>'site/index',	


'about-us' => 'page/AboutUs',

);

for above when i will run about-us.html it call page controller and AboutUs action.

Thanks

Pravin

Slug / Permalinks are generated separately to ensure that they are unique.

If you have any unique column into table which you’re gonna use for generating urls, then you can use it directly.

I couldn’t understand:

Do you mean you’re gonna make urls from many tables? Doesn’t seem good, but if its needed, may be a work around of having a separate table with minimum required columns like id, table_reference, slug and so on can be created and used for url creation.

Thus, a separate model representing that table could act as custom URL Rule class and moreover can also check slugs periodically for its existence or may be for redirecting to another slug with permanent redirection.

I have many models that need similar editable slugs for urls (work/title+of+work, person/name+of+person, news/2012/10/18/title+of+the+news+item). Pretty much similar functionality as in WordPress.

At first save the slug is created automatically, and then there is the option of changing the name of the slug while editing the model. Since the slug should be unique, I will use that as a permalink, too.

There could be 2 possible solutions:

  1. Have single table with all slug and extra columns which resolves the original table & row in it.

  2. Have a class doing resolution of table & row based on some unique identifier in slug.

I ended up using Sluggable Behaviour with "slug" columns on all tables.