Erennok
(Sluy1983)
July 25, 2012, 5:28am
1
Hello and good day.
I have a question about Yii.
I am creating a small CMS and I need to load pages from the database.
My problem is this;the site loads dynamic content from www.myweb.com/site/load.html?q=1234
This connect to the page 1234 and gets the content.
How I can delete the controller/action and convert the query to the name of the topic? like this www.myweb.com/my_topic_here.html
Thanks for your time.
chennaiiq
(Chennaiiq)
July 26, 2012, 12:48pm
4
Yah you can…
Add in .htaccess
# 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
Change in config=>main.php
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
.....
),
'showScriptName'=>false,
'urlSuffix'=>'.html',
),
Also you can change the rules based on your requirement like this
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/getpriority/<category:\d+>'=>'<controller>/getpriority',
'<controller:category>/<action:(create|index|admin)>'=>'<controller>/<action>',
'<controller:category>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:category>/<cat:.+>/'=>'<controller>/categorypage',
'<controller:article>/<action:(create|index|admin|slug|suggestTags)>'=>'<controller>/<action>',
'<controller:article>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:article>/<art:.+>/'=>'<controller>/articlepage',
'<controller:\w+>/slug/<st:.+>'=>'<controller>/slug',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
Erennok
(Sluy1983)
July 28, 2012, 12:09am
5
Changing rules has worked.
Thanks for help!.