Home > Backend Development > PHP Tutorial > 让Nginx支持ThinkPHP的URL重写跟PATHINFO

让Nginx支持ThinkPHP的URL重写跟PATHINFO

WBOY
Release: 2016-06-13 10:31:20
Original
965 people have browsed it

让Nginx支持ThinkPHP的URL重写和PATHINFO

实现让ThinkPHP在nginx上正确运行。

只需在配置文件中添加以下信息,就能让nginx正确解析ThinkPHP的网站。

?

?

    location /project/    {      index  index.php;      if (!-e $request_filename)      {        rewrite  ^/project/(.*)$  /project/index.php/$1  last;        break;      }    }      location ~ .+\.php($|/)    {      set $script    $uri;      set $path_info  "/";      if ($uri ~ "^(.+\.php)(/.+)")      {        set $script     $1;        set $path_info  $2;      }        fastcgi_pass 127.0.0.1:9000;      include fastcgi.conf;      fastcgi_index  index.php?IF_REWRITE=1;      fastcgi_param PATH_INFO $path_info;      fastcgi_param SCRIPT_FILENAME  $document_root/$script;      fastcgi_param SCRIPT_NAME $script;    }
Copy after login

这里先把project下的请求都转发到index.php来处理,亦即ThinkPHP的单一入口文件;然后把对php文件的请求交给fastcgi来处理,并且添加对PATH_INFO的支持。

重启Nginx以后,http://localhost/project/Index/insert, http://localhost/project/index.php/Index/delete 这样的URL都可以正确访问了。

还有一个地方需要注意的是,Nginx配置文件里 if 和后面的括号之间要有一个空格,不然会报unknown directive错误。

?

作者:?潺莪?发表于 2011-08-08 10:48?原文链接

?

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template