欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

thinkphp在低版本Nginx 下支持PATHINFO的方法分享

 更新時間:2016年05月27日 09:01:37   作者:hustnzj  
本文給大家分享的是如何讓thinkPHP在低版本的Nginx下支持PATHINFO去掉index.php路徑的方法,十分的簡單實用,思路也很巧妙,有需要的小伙伴可以參考下

最近在用thinkphp做一個項目,基本完成后部署到nginx服務器上才發(fā)覺nginx是不支持pathinfo的那么我們?nèi)绾蝸硖幚砟亍?/p>

Nginx環(huán)境

在Nginx低版本中,是不支持PATHINFO的,但是可以通過在Nginx.conf(在/usr/local/nginx/conf/nginx.conf或者通過find / | grep nginx.conf來查找位置)中配置轉(zhuǎn)發(fā)規(guī)則實現(xiàn):在nginx配置文件中添加:

location / { 
if (!-e $request_filename) {
   rewrite ^(.*)$ /index.php?s=$1 last;
   break;
 }
} 

其實內(nèi)部是轉(zhuǎn)發(fā)到了ThinkPHP提供的兼容模式的URL,利用這種方式,可以解決其他不支持PATHINFO的WEB服務器環(huán)境。
如果你的ThinkPHP安裝在二級目錄,Nginx的偽靜態(tài)方法設置如下,其中youdomain是所在的目錄名稱。

location /youdomain/ {
 if (!-e $request_filename){
  rewrite ^/youdomain/(.*)$ /youdomain/index.php?s=$1 last;
 }
} 

如:

location /thinkphp/ {
 if (!-e $request_filename){
    rewrite ^/thinkphp/(.*)$ /thinkphp/index.php?s=$1 last;
 }
}

語法:rewrite regex replacement flag  (last     相當于apache里面的[L]標記,表示rewrite。)

相關文章

最新評論