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

Yii2.0 implements the configuration method of pathinfo formal access

不言
Release: 2023-03-30 16:48:01
Original
1398 people have browsed it

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' => [
 ],
],
Copy after login

## 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
Copy after login

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;
 }
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
yii2 error connecting to mongodb3.2.4
From 1970-01-01 08:00:00
0
0
0
How to use mongodb to do rbac in yii2
From 1970-01-01 08:00:00
0
0
0
php - yii2-ueditor-widget
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template