Table of Contents
yii2.0实现pathinfo的形式访问的配置方法,yii2.0pathinfo
您可能感兴趣的文章:
Home php教程 php手册 yii2.0实现pathinfo的形式访问的配置方法,yii2.0pathinfo

yii2.0实现pathinfo的形式访问的配置方法,yii2.0pathinfo

Jun 13, 2016 am 08:41 AM
pathinfo yii2

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'=>[ 加到这里 ] ]中加入:

1

2

3

4

5

6

'urlManager' => [

 'enablePrettyUrl' => true,

 'showScriptName' => false,

 'rules' => [

 ],

],

Copy after login

此时,yii2.0已经支持以pathinfo的形式访问了,如果此时访问不了,继续往下看。

二.配置web服务器。

1.如果是apache,在入口文件(index.php)所在的目录下新建一个文本文件,接着另存为.htaccess,用记事本打开此文件加入:

1

2

3

4

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . index.php

Copy after login

保存即可。

2.如果是nginx,在nginx配置文件中加入:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

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

三:重启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的问题
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)