Yii 1.0 urlManager format URL
{Location}
>> protected/config/main.php
>> components
>> urlManager
{Basic Struction}
'urlManager'=>array(
'urlFormat'=>'path',
'rules'=>array(
//some rules here.
),
{Rule No. One}
>Rule
'posts'=>'post/list',
>Action
echo $this->createAbsoluteUrl('post/list');
>Display
http://yiilib.com/yii_lab/index.php/posts
{Rules No. Two}
>Rule
'post/<id:\d+>'=>array('post/show','urlSuffix'=>'.html'),
>Action
echo $this->createAbsoluteUrl('post/show',array('id'=>998, 'name'=>'123'));
>Display
http://yiilib.com/yii_lab/index.php/post/998.html?name=123
{Rules No.Three}
>Rule
'post/<id:\d+>/<mid:\w+>'=>array('post/view','urlSuffix'=>'.xml'),
>Action
echo $this->createAbsoluteUrl('post/view',array('id'=>998, 'mid'=>'tody'));
>Display
http://yiilib.com/yii_lab/index.php/post/998/tody.xml
{Rules No.Four}
>Rule
'http://<user:\w+>.yiilib.com/<_c:(look|seek)>'=>array('<_c>/host','urlSuffix'=>'.mp4'),
>Action
echo $this->createAbsoluteUrl('look/host',array('user'=>'BoyLee', 'mid'=>'ny-001'));
echo $this->createAbsoluteUrl('looks/host',array('user'=>'BoyLee', 'mid'=>'ny-002'));
>Display
http://BoyLee.yiilib.com/look.mp4?mid=ny-001
http://yiilib.com/looks/host/user/BoyLee/mid/ny-002
{Hidden index.php}
1.add showScriptName=>false
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
2.add ......./yii_lab/.htaccess , be brother with index.php and protected, and add this code in it.
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteBase /yii_lab
# 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
3.make .htaccess working ....
look at this
4.make sure your rewrite is open
anyway, good luck.^&^
Leave Comment