《PHP應用:yii2.0實現pathinfo的形式訪問的配置方法》要點:
本文介紹了PHP應用:yii2.0實現pathinfo的形式訪問的配置方法,希望對您有用。如果有疑問,可以聯系我們。
相關主題:YII框架
PHP學習yii2.0默認的拜訪形式為:dxr.com/index.php?r=index/list,一般我們都會配置成pathinfo的形式來拜訪:dxr.com/index/list,這樣更符合用戶習慣.
PHP學習具體的配置辦法為:
PHP學習一.設置裝備擺設yii2.0.
PHP學習打開config目錄下的web.php,在$config = [ 'components'=>[ 加到這里 ] ]中參加:
PHP學習
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
],
],
PHP學習
PHP學習此時,yii2.0已經支持以pathinfo的形式拜訪了,如果此時拜訪不了,繼續往下看.
PHP學習二.設置裝備擺設web服務器.
PHP學習1.如果是apache,在入口文件(index.php)所在的目錄下新建一個文本文件,接著另存為.htaccess,用記事本打開此文件參加:
PHP學習
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
PHP學習保留即可.
PHP學習2.如果是nginx,在nginx配置文件中參加:
PHP學習
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;
}
}
PHP學習三:重啟web服務器.
PHP學習至此,設置裝備擺設完畢.
《PHP應用:yii2.0實現pathinfo的形式訪問的配置方法》是否對您有啟發,歡迎查看更多與《PHP應用:yii2.0實現pathinfo的形式訪問的配置方法》相關教程,學精學透。維易PHP學院為您提供精彩教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/6966.html