I'm using this code to redirect url:
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.sendRedirect(newURL);
what I can see is a correct redirection but the value returned in the response is 302 instead of 301. How can I force it to 301?
If you use sendRedirect
, it will reset the status to 302. You'll have to use setHeader to set the Location header yourself to redirect using a 301 status.
Example code:
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location", "http://somewhere/");
Pulled from this answer: HttpServletResponse sendRedirect permanent
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With