yii2 url美化隐藏index.php

phpstudy环境:

yii2默认url是 :  http://localhost/myframe/basic/web/index.php?r=site%2Findex,

第一步:在应用配置文件config下的 web.php 中,在 ‘components’ 配置项里加入如下配置:

'urlManager' => [
'enablePrettyUrl' => true,//开启美化URL
'showScriptName' => false,//是否显示脚本名称:index.php,同时应该配置 Web 服务
'enableStrictParsing' => false,//是否开启严格解析
//'suffix' => '.html',//生成带 .html 后缀的 URL
'rules' => [

],
],

第二步 : 在web目录下加入 .htasccess 即可,内容如下:

<IfModule mod_rewrite.c>
Options +FollowSymlinks -Multiviews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L,E=PATH_INFO:$1]
</IfModule>

之前效果: http://localhost/myframe/basic/web/index.php?r=site%2Findex
最后效果: http://localhost/myframe/basic/web/site/index

ps:
  1.这是phpstudy环境下.htasccess 文件写法,其他自行百度;
  2. .htasccess 文件不要放错了,放在项目根目录无效,必须放在入口文件web目录下
  3.如果还有问题,请自行查看apache配置文件httpd.conf是否开启apache-rewrite;







猜你喜欢

转载自www.cnblogs.com/ybtxwd/p/9570503.html
今日推荐