How can I rewrite seo friendly url on struts?

by annabell_mcdermott , in category: SEO , 8 months ago

How can I rewrite seo friendly url on struts?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by cameron_walter , 8 months ago


To rewrite SEO friendly URLs on Struts, you can follow these steps:

  1. Define a new action mapping in struts-config.xml for the SEO friendly URL. For example, if you want to rewrite "" to "", add the following action mapping:
<action path="/products/{id}" type="com.example.ProductDetailsAction" parameter="id">
  <forward name="success" path="/"/>

  1. Create a new action class (e.g., ProductDetailsAction) that will handle the request for the rewritten URL. This class should extend the Action class and implement the execute method.
public class ProductDetailsAction extends Action {
  public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
    String id = request.getParameter("id");
    // Process the request and retrieve the product details based on the ID
    // Set the retrieved product details in the request attributes or form
    // Forward to the appropriate JSP or another action
    return mapping.findForward("success");

  1. Update the JSP or HTML pages to use the SEO friendly URLs instead of the original URLs. Replace links like Product Details with Product Details.
  2. Optionally, you can provide a link to redirect the old URL format to the new SEO friendly URL format. For example, if someone accesses the old URL "", you can redirect them to the new URL "" using a 301 redirect.

Remember to update your web server configuration (e.g., Apache) to rewrite the incoming SEO friendly URLs to the appropriate servlet or action URL. This can be achieved using Apache's mod_rewrite module or similar URL rewriting mechanisms depending on your web server.