Home > Backend Development > PHP Tutorial > location - nginx重写 index.php/ 为 i/

location - nginx重写 index.php/ 为 i/

WBOY
Release: 2016-06-06 20:30:40
Original
1527 people have browsed it

下面是我的CentOs服务器的nginx配置文件,现在已经正常可以访问index.php,但现在有一个重写需求,就是我输入23.abc.com/i/abc的时候重写为到23.abc.com/index.php/abc,即把index.php以i代替。请问在下面的基础上,应该如何修改?
server {

<code>    listen       80;
    server_name  23.abc.com;

    index index.html index.htm index.php;
    root  /home/wwwroot/test/;


            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;
                    fastcgi_pass unix:/tmp/php-cgi.sock;
                    fastcgi_index  index.php;
                    include fcgi.conf;
                    fastcgi_param  SCRIPT_FILENAME    $document_root$script;
                    fastcgi_param  SCRIPT_NAME        $script;
                    fastcgi_param  PATH_INFO          $path_info;

            }

    }
</code>
Copy after login
Copy after login

回复内容:

下面是我的CentOs服务器的nginx配置文件,现在已经正常可以访问index.php,但现在有一个重写需求,就是我输入23.abc.com/i/abc的时候重写为到23.abc.com/index.php/abc,即把index.php以i代替。请问在下面的基础上,应该如何修改?
server {

<code>    listen       80;
    server_name  23.abc.com;

    index index.html index.htm index.php;
    root  /home/wwwroot/test/;


            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;
                    fastcgi_pass unix:/tmp/php-cgi.sock;
                    fastcgi_index  index.php;
                    include fcgi.conf;
                    fastcgi_param  SCRIPT_FILENAME    $document_root$script;
                    fastcgi_param  SCRIPT_NAME        $script;
                    fastcgi_param  PATH_INFO          $path_info;

            }

    }
</code>
Copy after login
Copy after login

rewrite 23.abc.com/.*/abc 23.abc.com/index.php/abc break;

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