yii2.0实现pathinfo的形式访问的配置方法,yii2.0pathinfo
yii2.0实现pathinfo的形式访问的配置方法,yii2.0pathinfo
yii2.0默认的访问形式为:dxr.com/index.php?r=index/list,一般我们都会配置成pathinfo的形式来访问:dxr.com/index/list,这样更符合用户习惯。
具体的配置方法为:
一.配置yii2.0。
打开config目录下的web.php,在$config = [ 'components'=>[ 加到这里 ] ]中加入:
'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ],
此时,yii2.0已经支持以pathinfo的形式访问了,如果此时访问不了,继续往下看。
二.配置web服务器。
1.如果是apache,在入口文件(index.php)所在的目录下新建一个文本文件,接着另存为.htaccess,用记事本打开此文件加入:
RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . index.php
保存即可。
2.如果是nginx,在nginx配置文件中加入:
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; } }
三:重启web服务器。
至此,配置完毕。
您可能感兴趣的文章:
- 让Nginx支持ThinkPHP的URL重写和PATHINFO的方法分享
- PHP pathinfo()获得文件的路径、名称等信息说明
- 浅析ThinkPHP中的pathinfo模式和URL重写
- Nginx隐藏index.php和Pathinfo模式配置例子
- nginx支持codeigniter的pathinfo模式url重写配置写法示例
- nginx中配置pathinfo模式示例
- ThinkPHP中pathinfo的访问模式、路径访问模式及URL重写总结
- lnmp环境中如何为nginx开启pathinfo
- 解决nginx不支持thinkphp中pathinfo的问题

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to remove jquery from yii2: 1. Edit the AppAsset.php file and comment out the "yii\web\YiiAsset" value in the variable $depends; 2. Edit the main.php file and add the configuration "'yii" under the field "components" \web\JqueryAsset' => ['js' => [],'sourcePath' => null,]," to remove the jquery script.

This article will introduce you to the yii2 framework, share a few CTF exercises, and use them to learn the yii2 framework. I hope it will be helpful to everyone.

1. You need to download the windows version of the master branch of yii2-redis with composer 2. Unzip and copy it to vendor/yiisoft 3. Add 'yiisoft/yii2-redis'=>array('name'=>'yiisoft to extensions.php under yiisoft /yii2-redis','version'=>'2.0.

The reason is that I haven’t used Apache for a long time, and I gradually feel unfamiliar with Apache, because my friend has a zendframework framework that was moved from Apache to nginx and requires pathinfo mode support. So I started searching online for articles related to nginx+pathinfo. I thought it would be easy to configure it at first. After searching, I found that there are a lot of articles introducing nginx to enable pathinfo mode, and it seems that it is not difficult. But after several hours, it is still not configured properly. And the contents of a large number of articles are very similar, and they are basically reprinted. Starting to get a little anxious! Because one day has passed and the preparation has not been completed. There is no solution to continue groping, so continue searching. For the convenience of verification, I use a.c

In Yii2, there are two main ways to display error prompts. One is to use Yii::$app->errorHandler->exception() to automatically catch and display errors when an exception occurs. The other is to use $this->addError(), which displays an error when model validation fails and can be accessed in the view through $model->getErrors(). In the view, you can use if ($errors = $model->getErrors())

nginx configuration pathinfo hides index.php Put this code in the nginx configuration file server{listen80;default_typetext/plain;root/var/www/html;indexindex.phpindex.htmindex.html;#hide index.phplocation/{if(!- e$request_filename){#First-level directory#rewrite^/(.*)$/index.php/$1last;#Second-level directory rewrite^/myapp/(.*)$/myapp/

This article will explain in detail the information about the file path returned by PHP. The editor thinks it is quite practical, so I share it with you as a reference. I hope you can gain something after reading this article. PHP obtains file path information In PHP, you can obtain detailed information of a specified file path through the pathinfo() function. This function returns an array containing information about various parts of the file path. Syntax pathinfo(string$path,int$options=PATHINFO_DIRNAME|PATHINFO_BASENAME|PATHINFO_EXTENSION|PATHINFO_FILENAME) parameter $pat

To transfer apache to nginx, $_server['path_info'] is used on the code side. Pathinfo is not enabled by default for nginx. So we have to manually enable 1, url rewrite location/{//Method 1if(!-e$request_filename){rewrite^/(.*)$/index.php/$1last;break;}}location/{/ /Method 2try_files$uri$uri//index.php$uri;}2, pathinfo sets location~.
