Struts 2 redirects - permanent redirect option? 301 vs 302
Question
By default, Struts 2 "redirect" is a temporary redirect (302). This makes sense. However, for SEO purposes, I need to issue a permanent redirect (301). Is there an easy way to achieve this?
Solution
ServletRedirectResult has a statusCode
that should work. Try setting the statusCode
param on your redirect result. If you're using the Conventions plugin, something like:
@Result(name="success", location="/foo", type="redirect", params={"statusCode", "301"})
or the old style:
<result name="success" type="redirect">
<param name="location">/foo</param>
<param name="statusCode">301</param>
</result>
OTHER TIPS
The previous answer did not work for me. I solved it with a httpheader result:
301 /foo
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow