PHP CI框架的url路由配置

現在使用的nginx,這裏以版本爲1.10.3的nginx爲例,現在增加了try_files語法,比原來的rewrite路由的方式更加高效。

CI框架使用MVC框架,框架需要單一入口來處理請求,對於不存在的文件要做一下重新路由的功能,這是必需的。

爲了支持CodeIgniter框架, linux的  nginx 增加了一項配置,如下:

server {  
        listen 8000 default_server;  
        server_name newcar.site;
        root /var/www/newcar;
        index index.php index.html index.htm;   

        location / {  
            try_files $uri $uri/ /index.php;  
        }  
        location ~ \.php$ {  
            include snippets/fastcgi-php.conf;
            include fastcgi_params;
            fastcgi_pass   unix:/var/run/php/php7.0-fpm.sock;  
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO $fastcgi_path_info;
            fastcgi_split_path_info ^(.+\.php)(.*)$;
            fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        
        }  
    }

其中標黃的部分表示的意思其實就是rewrite機制,如果請求的文件不存在而且文件夾也不存在時,纔會跳轉到/index.php頁面


Windows下nginx的配置:


server {
        listen       80;
        server_name  newcar.xin.com ;
        root   "D:/phpStudy/WWW/x.xin.com";
		index  index.html index.htm index.php;
        location / {            
            try_files $uri $uri/ /index.php;
        }
        location ~ \.php(.*)$ {
			include uxin-conf.d/www_newcar.conf;
            include        fastcgi_params;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_split_path_info  ^((?U).+\.php)(/?.+)$;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_param  PATH_INFO  $fastcgi_path_info;
            fastcgi_param  PATH_TRANSLATED  $document_root$fastcgi_path_info;	
			
        }
		
}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章