美文网首页Yii2YII2.0
yii2.0去掉index.php

yii2.0去掉index.php

作者: 踏云小子 | 来源:发表于2016-12-30 18:35 被阅读26次

    1.开启apache的mod_rewrite模块

    • 去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符号
    • 确保DocumentRoot "/Library/WebServer/Documents"<Directory "..."></Directory>中有“AllowOverride All”
    • 重启apache
    sudo apachectl restart
    

    2.在项目中的/config/web.php中添加代码:

    components'=>array(            
      ...
    'urlManager' => [
                'enablePrettyUrl' => true,
                'showScriptName' => false,
                'rules' => [
                    '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
                ],
            ],           
     )
    

    3.在与index.php文件同级目录下(/web/)添加文件“.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
    
    • 注意:如果是Mac系统,".htaccess"文件是无法创建的,则要开启显示隐藏文件的功能:
    defaults write com.apple.finder AppleShowAllFiles -bool true
    

    再重启电脑,真是蛋疼,妈蛋

    over~

    相关文章

      网友评论

        本文标题:yii2.0去掉index.php

        本文链接:https://www.haomeiwen.com/subject/nxomvttx.html