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;
}
希望它有幫助。