diff --git a/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java b/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java index 18c0272112..a949263eb1 100644 --- a/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java +++ b/applications/content/src/main/java/org/apache/ofbiz/content/cms/CmsEvents.java @@ -31,6 +31,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; +import org.apache.commons.lang.StringUtils; import org.apache.ofbiz.base.util.Debug; import org.apache.ofbiz.base.util.GeneralException; import org.apache.ofbiz.base.util.GeneralRuntimeException; @@ -167,7 +168,7 @@ public class CmsEvents { GenericValue pathAlias = null; try { - pathAlias = EntityQuery.use(delegator).from("WebSitePathAlias").where("webSiteId", webSiteId, "pathAlias", pathInfo).orderBy("-fromDate").cache().filterByDate().queryOne(); + pathAlias = EntityQuery.use(delegator).from("WebSitePathAlias").where("webSiteId", webSiteId, "pathAlias", pathInfo).orderBy("-fromDate").cache().filterByDate().queryFirst(); } catch (GenericEntityException e) { Debug.logError(e, module); } @@ -179,16 +180,20 @@ public class CmsEvents { if (!alias.startsWith("/")) { alias = "/" + alias; } - RequestDispatcher rd = request.getRequestDispatcher(request.getServletPath() + alias); - try { - rd.forward(request, response); - } catch (ServletException e) { - Debug.logError(e, module); - return "error"; - } catch (IOException e) { - Debug.logError(e, module); - return "error"; - } + + String context = request.getContextPath(); + String location = context + request.getServletPath(); + GenericValue webSite = WebSiteWorker.getWebSite(request); + if (webSite != null && webSite.getString("hostedPathAlias") != null && !"ROOT".equals(pathInfo)) + location += "/" + webSite.getString("hostedPathAlias"); + + String uriWithContext = request.getRequestURI(); + String uri = uriWithContext.substring(context.length()); + uri = uri.substring(0, uri.lastIndexOf('/')); + + response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY); + response.setHeader("Location", location + uri + alias); + response.setHeader("Connection", "close"); return null; // null to not process any views }