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 onRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule . 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的問題

http://www.bkjia.com/PHPjc/1120003.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1120003.htmlTechArticleyii2.0實現pathinfo的形式訪問的配置方法,yii2.0pathinfo yii2.0預設的訪問形式為:dxr.com/index.phpr=index/list,一般我們都會配置成pathinfo的形式來訪...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.