Nginx mode supports the Thinkphp URL PATHINFO and REWRITE (Reprinted from the Wilmington csdn blog) next

1. Support PATHINFO

找到location ~ \.php {   ,把$去掉,并在里面加上这两句

fastcgi_split_path_info ^(.+\.php)(.*)$;     #增加
fastcgi_param PATH_INFO $fastcgi_path_info;    #增加

which is

location ~ \.php { #去掉$
    root       html
    fastcgi_pass   127.0.0.1:9000;
    fastcgi_index  index.php;
    fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include        fastcgi_params;
    fastcgi_split_path_info ^(.+\.php)(.*)$;     #添加
    fastcgi_param PATH_INFO $fastcgi_path_info;    #添加  好像新加的两行 位置最好放在这 放在别的地方不起作用~
}

2. Support REWRITE remove index.php

找到location / {  在里面加上

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

which is

location / {
    root       html 
    index  index.html index.htm index.php;

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

If thinkphp not deployed in the root directory of the site, namely the need to

rewrite  ^/(.*)$ /index.php?s=$1  last;
改成
rewrite  ^/子目录/(.*)$ /子目录/index.php?s=$1  last;

If there are multiple items in the root directory, you can write multiple rewrite:

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

After the restart nginx 

/etc/init.d/nginx restart

Published 21 original articles · won praise 3 · views 20000 +

Guess you like

Origin blog.csdn.net/zchare/article/details/80577987