• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

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

php 搞代码 3年前 (2022-01-25) 16次浏览 已收录 0个评论

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 onRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . index.php

保存即可。

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

server { listen    80; server_name localhost; <p>+本文来源gao!%daima.com搞$代*!码9网(</p><strong>搞gaodaima代码</strong>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服务器。

至此,配置完毕。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:yii2.0实现pathinfo的形式访问的配置方法_php实例

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址