Solving the problem of Nginx not supporting pathinfo in thinkphp _php skills

Source: Internet
Author: User

The following small series through the text plus code to everyone in detail, the specific contents are as follows:

In fact, to solve Nginx does not support pathinfo problem, there are two solutions, one is not to use PathInfo mode, the second is to modify the Nginx configuration file, so that it supports pathinfo. In order to simplify the problem, I chose the first way, because the second way, I looked at a lot of information, found that everyone's methods are not the same, and some also vary greatly, easy to cause misleading, so I choose to start from simple, choose common mode, although there are certain risks. When the index.php corresponding to the front code, found that the front desk is basically normal, but the background still has the problem of redirection. After a long time, I just thought to look at the log file, is the editor of the problem, it seems that the log file is really important, has not been valued before. The output appears in the first line of the config.php file.

In the sublime, the general will add a BOM header for the UTF-8 file, this BOM head under window is usually invisible, you can see through other editors, Linux can also see directly, usually show out is a garbled character, this character can be deleted, or simply, Directly in the first line of carriage return, and then deleted on it. Here, backstage basically can visit.

1. In the login, I was through the external JS file to send Ajax requests for verification, in the JS and thinkphp module function communication encountered some problems, has not known the right path to write, and did not find the relevant information, only a variety of tests, fortunately found a solution, By directly bringing the entry file name

var url= "System.php?m=login&a=dolog"; 
 $.post (url,{"staffname": $staffname, "staffpwd": $staffpwd, "Verifycode": $verifycode},function (data) { 
  if (data= = "Codeerr") { 
   alert ("Authentication code Error!)" "); 
  } else if (data== "Authempty") { 
   alert ("Please enter a username or password!") ") 
  }else if (data==" Autherr ") { 
   alert (" Wrong user name or password! ") "); 
  } else if (data== "Success") { 
   alert ("Login succeeded!") "); 
   Location.href= "System.php?m=index&a=index"; Access Home 
  } 

Of course, this is the normal mode of access, if it is pathinfo, only the red part of the following changes can be

var url= "Dolog"; 
 $.post (url,{"staffname": $staffname, "staffpwd": $staffpwd, "Verifycode": $verifycode},function (data) { 
  if (data = = "Codeerr") { 
    alert ("Authentication code Error!)" "); 
  } else if (data== "Authempty") { 
    alert ("Please enter a username or password!") ") 
  }else if (data==" Autherr ") { 
    alert (" Wrong user name or password! ") "); 
  } else if (data== "Success") { 
    alert ("Login succeeded!") "); 
    Location.href= ". /index/index "; Jump home, access to other modules of the method 

2. Download the file, always inexplicable more than a lot of html things, because the buffer is not empty, can be modified by the following code, but this way is actually downloading the file is still HTML format, but changed the suffix named XLS only, So when you open with Excel, you will be prompted to format problems, ignore it. Also note the use of the Icov () function to convert the encoding because the XLS default encoding format is not utf-8.

Ob_start (); 
Ob_end_clean (); 
Header ("Content-type:application/octet-stream"); 
Header ("Accept-ranges:bytes"); 
Header ("content-type:application/vnd.ms-excel;charset=gb2312");  
Header ("content-disposition:attachment;filename={$filename}.xls"); 

3. When you delete a file, you will encounter a path problem, because more of the project is relative path, that is, relative to the entry file, but delete the file will need to use the absolute path, I did not find the right solution, had to use a more conservative way

Copy Code code as follows:

$path = "./public/uploads/";
$path =str_replace ("<a target=" _blank "href=" file:///"style=" Color:rgb (51,119,170); Text-decoration:none ">\\" ","/", Realpath ($path)."  /</a> "); Gets the absolute path and converts the separator

4. In the configuration of Nginx and PHP, I used the fastcgi way, the following code saved as cmd file, directly click to run on it
"F:\php\php-cgi.exe"-B 127.0.0.1:9000-c "F:\php\php.ini"//Following is the path to the PHP file
And then add a few words to the Nginx configuration file.

Location ~ \.php/? * { 
   root   myapplications; 
   Fastcgi_pass 127.0.0.1:9000; 
    Fastcgi_index index.php; 
    Fastcgi_param script_filename $document _root$fastcgi_script_name; 
   Include  Fastcgi_params; 
   #定义变量 $path _info for storing pathinfo information 
    set $path _info ""; 
    #定义变量 $real _script_name for storing the real address 
    set $real _script_name $fastcgi _script_name; 
    #如果地址与引号内的正则表达式匹配 
    if ($fastcgi _script_name ~ "^ (. +?\.php) (/.+) $") { 
      #将文件地址赋值给变量 $real _script_name 
      Set $real _script_name $; 
      #将文件地址后的参数赋值给变量 $path _info 
      set $path _info $ 
    } 
    #配置fastcgi的一些参数 
    fastcgi_param script_filename $document _root$real_script_name; 
    Fastcgi_param script_name $real _script_name; 
    Fastcgi_param path_info $path _info; 
   } 

The above content is aimed at deploying thinkphp on the Nginx, solves the pathinfo problem, hoped can help everybody.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.