2

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?

n00b
  • 167
  • 1
  • 2
  • 8

2 Answers2

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
0

The previous answer did not work for me. I solved it with a httpheader result:

301 /foo

memg
  • 1