欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

yii随笔(三) 开启友好路径

程序员文章站 2022-05-20 13:06:03
...
概述:实现 localhost/site/login 访问 localhost/index.php?r=site/login

1. web server 配置

a. nginx 配置

location / {

try_files $uri $uri/ /index.php?$args;

}

b. apache 配置

DocumentRoot "webroot"

RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...

2. 在配置文件中的 components 里 添加如下(配置urlManager)

'urlManager' =>[
'class' => 'yii\web\UrlManager',
'showScriptName' => false,
'enablePrettyUrl' => true,
],

以上就介绍了yii随笔(三) 开启友好路径,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。