我尝试使用yii框架制作网站,并制作友好的网址。在 如果我使用友好的网址,如:
http://localhost/eshops/ -> calls protected/controllers/SiteController->actionIndex()
http://localhost/eshops/login -> calls protected/controllers/SiteController->actionLogin()
http://localhost/eshops/logout -> calls protected/controllers/SiteController->actionLogout()
...
但是如何使用另一个控制器AbcController,如
http://localhost/eshops/abc/a -> calls protected/controllers/AbcController->actionA()
http://localhost/eshops/abc/b -> calls protected/controllers/AbcController->actionB()
它没有显示“错误404”?
.htaccess是
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
规则在protected / config / main.php
中'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
'rules'=>array(
'gii'=>'gii',
'<action>'=>'site/<action>',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),
谢谢
答案 0 :(得分:1)
你需要记住执行规则的顺序!您只需设置正确的规则
即可'rules'=>array(
'gii'=>'gii',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'<action:(login|logout|register|contact)>' => 'site/<action>',
// or full access
// '<action:\w+>' => 'site/<action>',
),