Home > Backend Development > PHP Tutorial > nginx配置中rewrite的问题

nginx配置中rewrite的问题

WBOY
Release: 2016-06-06 20:28:48
Original
1406 people have browsed it

我想实现用户请求 x.com/api/dosomething 转发到网站根目录下的/api.php处理.
不存在的文件交给 /index.php处理,nginx配置如下

<code> if (!-e $request_filename) {
         rewrite (.*) /index.php$1 last;
     }

location ^~ /api/{
    rewrite (.*) /api.php$1 last;
}

location ~ (index|api|admin).php {
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param PATH_INFO $fastcgi_path_info;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     }</code>
Copy after login
Copy after login

但是我发现访问x.com/api/dosomething的时候匹配了 ! -e $request_filename,调准顺序也没有用,请问应该如何配置

回复内容:

我想实现用户请求 x.com/api/dosomething 转发到网站根目录下的/api.php处理.
不存在的文件交给 /index.php处理,nginx配置如下

<code> if (!-e $request_filename) {
         rewrite (.*) /index.php$1 last;
     }

location ^~ /api/{
    rewrite (.*) /api.php$1 last;
}

location ~ (index|api|admin).php {
         fastcgi_split_path_info ^(.+\.php)(/.+)$;
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         include fastcgi_params;
         fastcgi_param PATH_INFO $fastcgi_path_info;
         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
     }</code>
Copy after login
Copy after login

但是我发现访问x.com/api/dosomething的时候匹配了 ! -e $request_filename,调准顺序也没有用,请问应该如何配置

咋一看配置没错啊,我本地试试再说。。。

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