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?
Asked
Active
Viewed 3,603 times
2 Answers
2
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>

A Lee
- 7,828
- 4
- 35
- 49
-
Awesome. That works! However, statusCode=301 gets appended to the redirected URL when I do this =( – n00b May 13 '11 at 23:57
-
Ok, I was able to get around the bug by subclassing org.apache.struts2.dispatcher.ServletActionRedirectResult. I've overridden the method protected List
getProhibitedResultParams() to include "statusCode". – n00b May 14 '11 at 00:54