Nginx Rewrite 配置


这个是我现有的配置.

location / {
        index index.php;
    }

    location /request/ {
        rewrite ^/request/(.+)$ /request?model=$1 break;
    }

    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi_params;
        fastcgi_param REQUEST_METHOD $request_method;
    }

我现在要实现的是,当访问: /request/concact 路径时,rewrite 到/request/?model=contact

然后不丢失POST 参数并且浏览器不跳转。

现在这个配置给我的麻烦是,请求从POST rewrite成了GET, 并且地址做了跳转。

url-rewrite nginx php

lklrty 11 years, 6 months ago
rewrite ^/request/(.+)$ /request?model=$1 break;

这句第二个request后面加一个斜杠就好了:

rewrite ^/request/(.+)$ /request/?model=$1 break;
Aoki. answered 11 years, 6 months ago

Your Answer