301 Permanent Redirect

the smart way to do a redirect to something more permanent is not to do:

 
//standard re-direct
httpServletResponse.sendRedirect(newTargetUrl);

but do this instead:

//set to 301
httpServletResponse.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
httpServletResponse.setHeader("Location", newTargetUrl);
httpServletResponse.setHeader("Connection", "close");

the difference is that instead of sending a default 302, we are sending a 301, which is more seo and bot friendly. i would suspect that you would only use this in a case where the origination url is always going to goto the new target url, otherwise keep using the regular way.

Leave a Reply