Home >Backend Development >PHP Tutorial >Yii2.0 implements the configuration method of pathinfo formal access
This article mainly introduces the relevant information on the configuration method of yii2.0 to implement pathinfo form access. Friends in need can refer to it
The default access form of yii2.0 is: dxr.com/index .php?r=index/list, generally we will configure it in the form of pathinfo to access: dxr.com/index/list, which is more in line with user habits.
The specific configuration method is:
1. Configure yii2.0.
Open web.php in the config directory and add:
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ],
## in $config = [ 'components'=>[Add here] ]
#At this time, yii2.0 already supports access in the form of pathinfo. If you cannot access it at this time, continue reading.2. Configure the web server.
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.phpSave it. 2. If it is nginx, add:
server { listen 80; server_name localhost; 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; } }
to the nginx configuration file. Three: Restart the web server.
At this point, the configuration is complete. The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website! Related recommendations:How to export excel tables in the YII2 framework
The above is the detailed content of Yii2.0 implements the configuration method of pathinfo formal access. For more information, please follow other related articles on the PHP Chinese website!