HTTP 303是自定义重定向标头,不是错误,应在HTTP POST后使用。如果保留一些传统的网址是你想要的(对于SEO目的等),你可以考虑使用HTTP 301 - Moved Permanently头。
有几种方法存在任何HTTP请求重定向到两个的Http任何其他资源服务器和应用水平。我宁愿nginx/apache级别。举例nginx的:
server {
# ...
location ~ "^/category/([a-zA-Z0-9]+).html" {
# Example: http://www.example.com/category/product123.html
# The $1 will be product123
return 303 http://www.example.com/category/$1;
}
# ...
}
现在,调用重装HTTP服务器的配置之后,老/category/product123.html
URL将产生类似这样的回应:
HTTP/1.1 303 See Other
Server: nginx/1.X.0
Date: Tue, 07 Oct 2014 20:47:29 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 168
Connection: keep-alive
Location: http://www.example.com/category/prodct123
在应用层面上,你可以很容易地重定向内的任何请求控制器操作返回有效的Response对象:
public function anyControllerAction()
{
$response = $this->getResponse();
$response->getHeaders()->addHeaderLine('Location', 'http://www.example.com/category/prodct123');
$response->setStatusCode(303);
return $response;
}
希望它有帮助。