一些页面的 Yii 1.1 路由

Yii 1.1 routes for some pages

我对路线很陌生。

该网站是在 Yii 1.1 中编写的,因为它对我来说很容易编写。现在我想要

指向

我尝试过不同的方法,但都没有成功。

以下是我尝试配置路由的方式:

'urlManager' => array(
    'rules' => array(
        '<alias:admin>' => 'admin/index',
        '<alias:admin>' => 'site/<alias>',
        '<controller:\w+>' => '<controller>/view',
        'admin' => 'admin/index',
        'admin/index' => 'admin',
    ),
),

解决方法是什么?

要删除 ?r= 部分,您必须将 url 格式设置为 "path",在您的配置文件中:

array(
    ......
    'components'=>array(
        ......
            'urlManager'=>array(
            'urlFormat'=>'path',
        ),
    ),
);

我没有测试过,但你的路由配置应该是:

array(
    'admin' => 'admin/index',
)

并且要摆脱 index.php,您将必须更改您的 apache 配置(如果您显然正在使用 apache)

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

您将在文档中找到更详细的解释:http://www.yiiframework.com/doc/guide/1.1/en/topics.url