【YII是个什么鬼】YII入门——URL Manager配置

第一步:开启apache的rewrite模块

(1)去掉LoadModule rewrite_module modules/mod_rewrite.so前面的注释
(2)将<Directory "${SRVROOT}/htdocs">中的AllowOverride None设置为AllowOverride All
 
第二步:设置YII项目中config目录下的web.php文件,在components参数中新增:
          'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false
           ], 
 
第三步:在YII项目中的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
 
 
以上三步,缺一不可。
 
设置完以上,原始的URL如:basic/web/index.php?r=site/index,将对应为:basic/web/site/index
如果想要更多自定义的效果,则设置urlManager中的rules参数。
原文地址:https://www.cnblogs.com/anywing/p/4671581.html