(一)在配置Web的配置文件中加入
“components” => [
"urlManager" => [
//用于表明urlManager是否启用URL美化功能,在Yii1.1中称为path格式URL,
// Yii2.0中改称美化。
// 默认不启用。但实际使用中,特别是产品环境,一般都会启用。
"enablePrettyUrl" => true,
// 是否启用严格解析,如启用严格解析,要求当前请求应至少匹配1个路由规则,
// 否则认为是无效路由。
// 这个选项仅在 enablePrettyUrl 启用后才有效。
"enableStrictParsing" => false,
// 是否在URL中显示入口脚本。是对美化功能的进一步补充。
"showScriptName" => false,
// 指定续接在URL后面的一个后缀,如 .html 之类的。仅在 enablePrettyUrl 启用时有效。
"suffix" => "",
"rules" => [
"<controller:\w+>/<id:\d+>"=>"<controller>/view",
"<controller:\w+>/<action:\w+>"=>"<controller>/<action>"
]
],
],
(二) 配置伪静态
① 如果在wamp的集成环境当中(Apache)
请在httpd-vhosts.conf配置中,对应加入如图所示
② 如果是在phpstudy的集成环境中(Apche)
可以直接在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
③ 在linux下的话两者都可选用,当然nginx的话,需要在nginx的配置文件中加入伪静态命令,这里不详细介绍,可到YII的官方文档查阅相关资料