Jahia WCM SEO Friendly URLs

Nov 09, 2011
Oshyn Labs

In Enterprise environments, Jahia can be installed over other application Servers like JBoss. So in this post I want to explain how urlrewrite works with the Java API Tuckey that can be integrated in Jahia Enterprise installations. Also Jahia WCM can easily be leveraged to create SEO (Search Engine Optimization) Friendly URLs by your content editors.

Tuckey is a Java filter that permits J2EE web applications to implement urlrewrite based on the Apache mod_rewrite. This filter uses a configuration file called urlrewrite.xml located in the WEB-INF directory of your application. The way to enable Tuckey in JBoss is to modify the web.xml file of the instance for which you want to enable rewrite. This file is located in the WEB-INF directory and you need to enable Tuckey filter including the following configuration:


<filter>
          <filter-name>UrlRewriteFilter</filter-name>
          <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
           <init-param>
               <description>
                   set the amount of seconds the conf file will be checked for reload
               </description>
               <param-name>confReloadCheckInterval</param-name>
               <param-value>20</param-value>
           </init-param>
           <init-param>
               <description>
                   sets up log level
       </description>
               <param-name>logLevel</param-name>
               <param-value>INFO</param-value>
           </init-param>
    </filter>
    <filter-mapping>
       <filter-name>UrlRewriteFilter</filter-name>
               <url-pattern>/*</url-pattern>
    </filter-mapping>


Note that in the mapping section we are applying the UrlRewriteFilter to all the requests, and in the Filter section we are configuring the location of the filter class using the qualified name org.tuckey.web.filters.urlrewrite.UrlRewriteFilter. You need to be sure that the Tuckey jar is in the classpath of the web application. You can put that jar in the folder WEB-INF/lib/ of your JBoss installation. Now urlrewrite is enabling and you can put your rules in the file urlrewrite.xml located in the WEB-INF folder.

From the editor perspective it is easy to assign friendly URLs. The following screenshot shows how easy it is to assign a friendly url to a Jahia page. The content author just needs to go to the Page settings option and assign a Page URL Key containing the URL alias for the current page.



Example

A situation to use JBOSS rewrite rules for is when you have an Apache server acting as a Proxy in front of your JBoss Application Server. To configure Apache to act as a proxy you need to connect via ajp to the JBoss server. To do that you need to add the following code in the default VirtualHost configuration:


ProxyPass / ajp://192.168.2.110:8009/jahia/cms/
ProxyPassReverse / ajp://192.168.2.110:8009/jahia/cms/


Where jahia/cms is the location of jahia instance.


Then you need to add the proper rules in the urlrewrite.xml in order that images and friendly urls appear correctly. Following is a sample rule that makes correct calls to the template resources used in the template set like css and template images.


<rule>
        <note>
            Template resources rule
        </note>
        <from>/cms/jahia/templates/</from>
        <to last="true">/templates/</to>
</rule>