Home  >  Article  >  Backend Development  >  Nginx Rewrite 配置

Nginx Rewrite 配置

WBOY
WBOYOriginal
2016-06-06 20:51:25897browse

这个是我现有的配置.

	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, 并且地址做了跳转。

回复内容:

这个是我现有的配置.

	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, 并且地址做了跳转。

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

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

rewrite ^/request/(.+)$ /request/?model=$1 break;
Statement:
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