yii2.0配置以pathinfo的形式訪問,yii2.0pathinfo_PHP教程

來源:互聯網
上載者:User

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

至此,配置完畢。

文章出自:http://www.daixiaorui.com/read/218.html 本站所有文章,除註明出處外皆為原創,轉載請註明本文地址,著作權。

http://www.bkjia.com/PHPjc/1116659.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1116659.htmlTechArticleyii2.0配置以pathinfo的形式訪問,yii2.0pathinfo yii2.0預設的訪問形式為:dxr.com/index.php?r=index/list,一般我們都會配置成pathinfo的形式來訪問:dx...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.