I am using the code like:
@RequestMapping(value="/oldPath")
public String doProductOld(
@PathVariable(value = "oldProductId") Long oldProductId,
Model model
) throws Exception {
Product product = productDao.findByOldId(oldProductId);
return "redirect:" + product.getUrlNewPath();
}
All works fine but this redirect returns 302
response code instead of 301
which is needed for SEO. How to easily (without ModelAndView
or Http response) update it to return 301
code?
PS. I found solutions when ModelAndView
object return from controller but need solution for Tiles
when tiles alias (String) is returned.
General idea is:
@RequestMapping(value="/oldPath")
public ModelAndView doProductOld(
@PathVariable(value = "oldProductId") Long oldProductId,
Model model
) throws Exception {
Product product = productDao.findByOldId(oldProductId);
RedirectView red = new RedirectView(product.getUrlNewPath(),true);
red.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
return new ModelAndView(red);
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다