Home  >  Article  >  Backend Development  >  Yii2.0 implements the configuration method of pathinfo formal access

Yii2.0 implements the configuration method of pathinfo formal access

不言
不言Original
2018-06-08 10:16:551283browse

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.

1. If it is apache, create a new text file in the directory where the entry file (index.php) is located, then save it as .htaccess, open this file with Notepad and add:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

Save 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn