@H_301_0@yii2.0默认的访问形式为:dxr.com/index.PHP?r=index/list,一般我们都会配置成pathinfo的形式来访问:dxr.com/index/list,这样更符合用户习惯。
@H_301_0@具体的配置方法为: @H_301_0@一.配置yii2.0。
@H_301_0@打开config目录下的web.PHP,在$config = [ 'components'=>[ 加到这里 ] ]中加入: [
'enablePrettyUrl' => true,'showScriptName' => false,'rules' => [
],],
@H_301_0@
@H_301_0@此时,yii2.0已经支持以pathinfo的形式访问了,如果此时访问不了,继续往下看。
@H_301_0@二.配置web服务器。
@H_301_0@1.如果是apache,在入口文件(index.PHP)所在的目录下新建一个文本文件,接着另存为.htaccess,用记事本打开此文件加入:PHP;">
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.PHP
@H_301_0@保存即可。
@H_301_0@2.如果是Nginx,在Nginx配置文件中加入:
PHP;">
server {
listen 80;
server_name localhost;
@H_301_0@location / {
root E:/wwwroot/yii2.0;
index index.html index.PHP;
if (!-e $request_filename){
rewrite ^/(.*) /index.PHP last;
}
}
location ~ .PHP$ {
root E:/wwwroot/yii2.0;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.PHP;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}