Friendly URLs
1 Purpose
With eXo WCM you can simply use the Content List Viewer portlet (CLV) in conjunction with the Parameterized Content Viewer portlet (PCV) in order to simply display a list of content and their details. By default, WCM content URLs are pointing directly to the file located within the JCR storage structure, so the URL path contains technical elements inside. For example, the URL of a WCM content can be as complex as that:http://localhost:8080/portal/private/vitrines/products/presentation/pcv/repository/collaboration/sites%20content/live/vitrines/web%20contents/site%20artifacts/Toute%20Actualite/Numero%20appel%20urgence%20europeenhttp://localhost:8080/portal/article/My-Personal-Article
http://localhost:8080/portal/article/2009/11/27/My-Personal-Article
2 URL Rewrite Filter
Download and unzip the http://tuckey.org/urlrewrite/#download zip file and put the jar file somewhere in the server classpath. Add the following lines to the exoplatform portal.war web.xml file.<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
...
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>2.1 Rewriting Rule Configuration File
Put a urlrewrite.xml file in the WEB-INF directory of the portal.war. Define the following rewriting rule in the file:<rule>
<note>
The rule means that requests to /article/myarticle will be forwarded to
/public/classic/mypage/repository/collaboration/myfolder/myarticle
the url will be rewritten.
</note>
<from>/article/(.*)</from>
<to>/public/classic/mypage/repository/collaboration/myfolder/$1</to>
</rule>3 Demonstration
Now let's do a simple page to show how all this works.3.1 Page Layout
Create a new page named 'mypage' in WCM, at the root of the portal navigation and put a CLV and a PCV inside.
3.2 Configuration
Configure the CLV to point to the right JCR path (where the is content) and the target page to 'mypage' because the CLV and PCV are both on the same page.
3.3 CLV Template Modification
Open the Sites administration / DMS Administration drive. Then go to the "/exo:ecm/views/templates/Content List Viewer/list-by-folder" folder. Edit the UIContentListPresentationDefault.gtmpl content, which is the template we choose for the CLV (see also WCM Templates. Locate the following block of code and insert the line below: itemLink = "/portal/article/$itemName"... for (Node node : currentPageData) { def viewNode = Utils.getNodeView(node); if (viewNode == null) continue; String itemLink = uicomponent.getURL(viewNode); String itemName = viewNode.getName(); itemLink = "/portal/article/$itemName" String itemSummary = uicomponent.getSummary(viewNode); ...
4 Conclusion
That's it! Now you have clean and friendly URLs for your contents. Look to URL in the address bar and to the status bar when moving the mouse over content titles in the CLV. You can see that URLs are short and clean.
5 Overcome the Restrictions
Some restrictions apply to this URL rewriting trick, mainly the highly generic URL that cover all kind of use-cases is replaced by a more restricted single use-case URL. This solution entails several drawbacks:- The page name, the workspace and the folder are hard-coded in the URL rewriting rule. This rewriting rule is applied to all CLV instances that use the modified viewer template. In fact in the viewer template "UIContentListPresentationDefault.gtmpl" you hard-code the shortcut URL "/portal/article/$itemName" for which the rewriting rule is applied.
- All articles pointed by any of these CLV instances must be in the same workspace (in this example "collaboration").
- All articles pointed by any of these CLV instances must be in the same folder (in this example "myfolder").
- All articles pointed by any of these CLV instances must be in the same portal/site (in this example "classic").
- By shortcutting the URL you can only point to the same page. Pointing to other pages from a CLV that uses this template will not work.
on 15/12/2009 at 17:03