ville
(Villeskants)
June 16, 2013, 7:18pm
1
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.
konapaz
(Konapaz)
June 16, 2013, 7:54pm
2
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>',
ville
(Villeskants)
June 16, 2013, 8:02pm
3
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>',
),
),
Tsunami
(Erik)
June 16, 2013, 8:17pm
4
index.php is not part of a route.
echo CHtml::link($model->name, $this->createUrl('category/products', array('id' => $model->id))
konapaz
(Konapaz)
June 16, 2013, 8:20pm
5
Tsunami:
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
ville
(Villeskants)
June 16, 2013, 8:28pm
6
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.
ville
(Villeskants)
June 16, 2013, 8:35pm
7
This was the problem I guess, it should have been in the document root, not in protected-directory. Works now.
Tsunami
(Erik)
June 16, 2013, 8:36pm
8
The .htaccess in the protected folder is there for a reason though, make sure to put the original back.
konapaz
(Konapaz)
June 16, 2013, 8:38pm
9
ville:
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.
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”