Routes Problem

Hey,

How should I configure the rules in config/main.php in order to have url-structure like this:

index.php/category/products/2

Right now I’m getting urls like this index.php/category/products/id/2 using CHtml::link()-method:

echo CHtml::link($model->name, $this->createUrl(‘index.php/category/products’, array(‘id’ => $model->id))

So how can I get rid of that last "id" parameter?

Thanks in advance.

Hi @ville

explain us what are category and products ( controller and action ?)

Also post your urlManager’s rules

In addition, did you check something like that ?


'<controller:\w+>/<controller:\w+>/<id:\d+>' => '<controller>/<action>',

Hi,

category refers to a controller and this controller has an action called products. At the moment I have default rules in config/main.php.


		

'urlManager'=>array(

			'urlFormat'=>'path',

			'showScriptName'=>false,

			'caseSensitive'=>false,

			'rules'=>array(

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

				'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',		

				'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',

			),

		),



index.php is not part of a route.


echo CHtml::link($model->name, $this->createUrl('category/products', array('id' => $model->id))

I agree with @Tsunami

I didn’t see that!

check also the documentation

http://www.yiiframework.com/doc/guide/1.1/en/topics.url

Thanks,

so far I haven’t got rid of index.php from the url. I have read Yii documentation and several topics here but none of them have offered a solution.

My .htaccess-file is located inside protected-directory with the following content:




deny from all

RewriteEngine on


# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d


# otherwise forward it to index.php

RewriteRule . index.php



Besides these, apache Mod rewrite is enabled and there is no other .htaccess in parent folder which would conflict maybe.

This was the problem I guess, it should have been in the document root, not in protected-directory. Works now.

The .htaccess in the protected folder is there for a reason though, make sure to put the original back.

why your htaccess has all of them? the official generated htaccess by yii has only "deny from all"

Do you want more protection? then this file have to moved in root folder, don’t forget to has also one .htaccess in protected folder with “deny from all”