yii2.0配置以pathinfo的形式访问

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' => [

  ],

],

yii配置pathinfo

此时,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  www.daixiaorui.com;

 

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服务器。

 

转载于:https://www.cnblogs.com/iceman-/p/8335425.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值