1.修改Apache的配置httpd.conf (1)开启apache的mod_rewrite模块去掉LoadModule rewrite_module modules/mod_rewrite.so前的“#”符号 (2)确保<Directory "..."></Directory>中有“AllowOverride All” 批注:对于wamp而言,第二个AllowOverride All已经开启。 AllowOverride在Apache的配置文件出现三次,但是只有一个地方需要 All,其他两个地方都是None。 (3)重启Apache 2.在项目中的/protected/config/main.php中添加代码:
Php代码  收藏代码
  1. 'components'=>array(
  2.             ...
    1.             'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ''=>'site/index' ], ],
  3.             ...
  4.         ),
3.在与index.php文件同级目录下添加文件“.htaccess”,内容如下:
Shell代码  收藏代码
  1. Options +FollowSymLinks
  2.  IndexIgnore */*
  3.  RewriteEngine on
  4.  # if a directory or a file exists, use it directly
  5.  RewriteCond %{REQUEST_FILENAME} !-f
  6.  RewriteCond %{REQUEST_FILENAME} !-d
  7.  # otherwise forward it to index.php
  8.  RewriteRule . index.php
批注:这段在yii的官方指南中也有: 详见:http://www.yiiframework.com/doc/guide/2/zh_cn/topics.url

分类: web

标签: