yii实现伪静态

一:

调整apache配置文件httpd.conf,重启apache服务器。。。


1. 装载rewrite_module模块

LoadModule rewrite_module modules/mod_rewrite.so


2. 相对应目录的AllowOverride修改为ALL

DocumentRoot "/Users/dream/Documents/Sites"
<Directory "/Users/dream/Documents/Sites">




    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/trunk/mod/core.html#options
    # for more information.
    #
    #Options Indexes FollowSymLinks
    # XAMPP
    Options Indexes FollowSymLinks ExecCGI Includes


    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    #AllowOverride None
    # since XAMPP 1.4:
    AllowOverride All


    #
    # Controls who can get stuff from this server.
    #
    Require all granted
</Directory>


二 确保apache加载mod_rewrite模块,通过phpinfo()查看(http://localhost/xampp/)


三 在根目录下,即在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
RewriteRule  ^(?!server-status).*?$ index.php


四 编辑配置yii的配置文件main.php,配置urlManager组件

'urlManager'=>array(
'urlFormat'=>'path', //改为path格式路径
                        'showScriptName'=>false,//去掉index.php
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
),
),

你可能感兴趣的:(yii实现伪静态)