custom url rewriting

hi,

i’m new in yii framework

i’m developping a website that sell a some products (PCs , cars, tables …) each product is affected to a subcategory and category, visitors of the website can list products by category or subcategory.

i would like to use friendy urls for listing pages

listing by category witch have id = 1 :

default url :


www.site.com/index.php?r=category/index?id=1

to become :


www.site.com/category_name.html

with pagination to become :


www.site.com/category_name_page.html

listing by sybcategory witch have id = 20 :

default url :


www.site.com/index.php?r=subcategory/index?id=20

to become :


www.site.com/category_name/subcategory_name.html

with pagination to become :


www.site.com/category_name/subcategory_name_page.html

page showing product details

default url :


www.site.com/index.php?r=product/show?id=4000

to become :


www.site.com/category_name/subcategory_name/product_name.html

any one can help me how to transform this urls using yii urlmanager or .htaccess

and how to use createURL or createAbsoluteUrl with the new urls

thanks for your help

any help please ?

I’d like to advice you to change a bit your goal.

If you do like that, a category that unfortunately has the name of a controller or action will make a slug conflict.

Better to use discriminators, for example:

www.site.com/cat_category_name_page.html

This can be achived with this rules:




'cat-<category_name[a-z0-9_]+>-<Category_page:[\d]+>'=>'/',

'cat-<category_name[a-z0-9_]+>'=>'/',



Please, note that this url allows you to use letters, number and _ for category name, while - you will use for separate the part of url.

With such url you will not have problems.