yii如何去掉index.php
这篇文章给大家分享的是有关yii如何去掉index.php的内容。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。
yii去掉index.php的方法:1、开启apache的mod_rewrite模块,并重启apache;2、编辑项目中的/config/web.php文件;3、在与index.php文件同级目录下添加【.htaccess】文件。
具体方法:
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>', ], ], )
(视频教程推荐:php视频教程)
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
感谢各位的阅读!关于yii如何去掉index.php就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到吧!