解决nginx不支持thinkphp中pathinfo的问题_php技巧
下面小编通过文字加代码的方式给大家详解下,具体内容如下:
其实,要解决nginx不支持pathinfo的问题,有两个解决思路,一是不使用pathinfo模式,二是修改nginx的配置文件,使它支持pathinfo。为了使问题简单化,我选择了第一种方式,因为就第二种方式,我查了很多资料,发现大家的方法不尽相同,有的还差别很大,容易造成误导,所以我选择从简出发,选择普通模式,虽然有一定的风险。当把index.php对应的前台代码修改完毕之后,发现前台基本正常,可是后台仍然出现重定向的问题。折腾了半天之后,我才想到看一下日志文件,原来是编辑器的问题,看来日志文件真的很重要,以前一直不重视。在config.php文件的第一行出现了输出,
在sublime下,一般会为UTF-8文件添加BOM头,这个BOM头在window下通常是看不见的,可以通过其他的编辑器查看到,Linux下也可以直接看到,通常显示出来是一个乱码字符,把这个字符删除即可,或者简单一点,直接在第一行回车,再删除就可以了。到这里,后台基本可以访问了。
1.在登录的时候,我是通过外部js文件发送Ajax请求进行验证的,在js与ThinkPHP模块函数通信遇到了点问题,一直不知道正确的路径该怎么写,也没有查到相关资料,只能各种试,好在找到了解决办法,通过直接带上入口文件名的方式
var url="system.php?m=Login&a=doLog"; $.post(url,{"staffname":$staffname,"staffpwd":$staffpwd,"verifycode":$verifycode},function(data){ if(data=="codeerr"){ alert("验证码错误!"); }else if(data=="authempty"){ alert("请输入用户名或密码!") }else if(data=="autherr"){ alert("用户名或密码错误!"); }else if(data=="success"){ alert("登录成功!"); location.href="system.php?m=Index&a=index"; //访问首页 }
当然,此为普通模式下的访问方式,如果是pathinfo的话,只需要把红色部分如下修改即可
var url="doLog"; $.post(url,{"staffname":$staffname,"staffpwd":$staffpwd,"verifycode":$verifycode},function(data){ if(data=="codeerr"){ alert("验证码错误!"); }else if(data=="authempty"){ alert("请输入用户名或密码!") }else if(data=="autherr"){ alert("用户名或密码错误!"); }else if(data=="success"){ alert("登录成功!"); location.href="../Index/index"; //跳转首页,访问其他模块的方法
2.下载文件的时候,总是莫名多出许多html的东西,原因是缓冲区没有清空,可以通过以下代码进行修改,不过这种方式实际上是下载的仍然是html格式的文件,只不过改了一下后缀名为xls而已,因而用excel打开的时候会提示格式问题,忽略即可。同时需要注意使用 icov()函数转换编码,因为xls默认编码格式并非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.在删除文件时会遇到路径问题,因为项目中使用的较多的是相对路径,即相对入口文件而言,但是删除文件则需要使用绝对路径,我并没有找到合适的解决方法,只好用了比较保守的方式
$path="./Public/uploads/";
$path=str_replace("file:///" style="color:rgb(51,119,170); text-decoration:none">\\","/",realpath($path)."/"); //获取绝对路径,并转换分隔符
4.在配置nginx和php方面,我使用了fastCGI的方式,将如下代码保存为cmd文件,直接点击运行就可以了
"F:\php\php-cgi.exe" -b 127.0.0.1:9000 -c "F:\php\php.ini" //后面是php文件的路径
然后在nginx的配置文件里加上几句话
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 ,用于存放pathinfo信息 set $path_info ""; #定义变量 $real_script_name,用于存放真实地址 set $real_script_name $fastcgi_script_name; #如果地址与引号内的正则表达式匹配 if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { #将文件地址赋值给变量 $real_script_name set $real_script_name $1; #将文件地址后的参数赋值给变量 $path_info set $path_info $2; } #配置fastcgi的一些参数 fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; }
以上内容是针对在Nginx上部署ThinkPHP,解决Pathinfo问题,希望能够帮助到大家。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Alipay PHP...

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
