首页 > 代码库 > Yii隐藏单入口

Yii隐藏单入口

         Yii进入项目首页时默认是index.php文件路径,如何把index.php去掉,方法如下:

         打开apache配置文件http.conf,找到如下的代码:

         #LoadModule rewrite_module modules/mod_rewrite.so

          把前面的#号去掉。

          往下继续查找,找到<Directory "d:/wamp/www/">,即服务器所在的目录,

           AllowOverride all

           AllowOverride 后面改为all,如上所示。

           重启apache.

           --------------------------------------------------------------------------------------

           打开Yii项目下的配置文件config/main.php,找到

           /*
             ‘urlManager‘=>array(
             ‘urlFormat‘=>‘path‘,
             ‘rules‘=>array(
            ‘<controller:\w+>/<id:\d+>‘=>‘<controller>/view‘,
            ‘<controller:\w+>/<action:\w+>/<id:\d+>‘=>‘<controller>/<action>‘,
            ‘<controller:\w+>/<action:\w+>‘=>‘<controller>/<action>‘,
            ),
           ),
           */ 

           把注释去掉,改成

            ‘urlManager‘=>array(
             ‘urlFormat‘=>‘path‘,

             ‘showScriptname‘=>false,
             ‘rules‘=>array(
            ‘<controller:\w+>/<id:\d+>‘=>‘<controller>/view‘,
            ‘<controller:\w+>/<action:\w+>/<id:\d+>‘=>‘<controller>/<action>‘,
            ‘<controller:\w+>/<action:\w+>‘=>‘<controller>/<action>‘,
            ),

           ),

         -------------------------------------------------------------------------------------

          最后,在index.php同级目录下添加.htaccess文件:

          Options +FollowSymLinks

          IndexIgnore */*

         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