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的形式來訪...