>  기사  >  php教程  >  yii2.0实现pathinfo的形式访问的配置方法,yii2.0pathinfo

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

WBOY
WBOY원래의
2016-06-13 08:41:45703검색

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的问题
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.