How to personalize URLs
In this section
Configuring Jahia's context and servlet path
Documentation to change the default /jahia/Jahia mapping to a custom context path and servlet path config.
In this document we assume that :
- CONTEXT_NAME will be your new context name (must be set to an empty string if you want to use Jahia as the default (ROOT) web application).
- SERVLET_NAME will be your new servlet name.
- That you have already installed Jahia previously, and will modify this configuration from an existing setup.
Also, be careful when modifying paths. Usually you will only modify paths that START with the /jahia context, not paths that contains the jahia context. So for example :
/jahia/jsp/jahia/templates/
will become :
/CONTEXT_NAME/jsp/jahia/templates
but NOT :
/CONTEXT_NAME/jsp/CONTEXT_NAME/templates
You should avoid using search and replace as you need to be careful with these modifications. Some Jahia names will have to be left in place, such as the <servlet-name> parameter that must not change. This Jahia can be left alone as it is not a problem as it will never be displayed to the user anyway.
-
Rename your the tomcat/webapps/jahia directory to tomcat/webapps/CONTEXT_NAME.
If you want to install Jahia as the ROOT (default) web application, CONTEXT_NAME == ROOT. In this case you will also first to have to rename Tomcat's default ROOT directory to something else, like tomcatROOT, or simply delete it if you don't need it.
If using the default web application (ROOT) configuration, you must also rename Tomcat's default webdav web application in tomcat/webapps/webdav to something else, as it will conflict with Jahia's webdav servlet mapping. Or you could remove it completely if you don't intend on using Tomcat's webdav servlet (recommended).
-
Rename the
tomcat/conf/Catalina/localhost/jahia.xmlfile totomcat/conf/Catalina/localhost/CONTEXT_NAME.xml -
Open tomcat/conf/Catalina/localhost/CONTENT_NAME.xml
Modify the following line, replacing the /jahia with your CONTEXT_NAME :
<Context path="/jahia" docBase="jahia" crossContext="true">
gets modified to :<Context path="/CONTEXT_NAME" docBase="CONTEXT_NAME" crossContext="true">
In the case of a default web application (ROOT) configuration, this is a bit different, you will use an empty string for the path :<Context path="" docBase="CONTEXT_NAME" crossContext="true">
-
In tomcat/webapps/CONTEXT_NAME/WEB-INF/web.xml
Replace occurrences of /jahia with your /CONTEXT_NAME
Replace occurrences of /Jahia with your SERVLET_NAME
in the following sections
for the Jahia servlet :
<init-param> <!-- This parameter specifies the default mapping pattern that Jahia should use when generating URLs or detecting Jahia content URLs. If you change anything to the mappings you need to change this too. --> <param-name>defaultMappingPattern</param-name> <param-value>/Jahia/*</param-value> </init-param> <init-param> <!-- This parameter defines the default context path that will be used to generate URLs --> <param-name>defaultContextPath</param-name> <param-value>/jahia</param-value> </init-param> <init-param> <!-- This parameter defines the default servlet path that will be used to generate URLs --> <param-name>defaultServletPath</param-name> <param-value>/Jahia</param-value> </init-param>to :<init-param> <!-- This parameter specifies the default mapping pattern that Jahia should use when generating URLs or detecting Jahia content URLs. If you change anything to the mappings you need to change this too. --> <param-name>defaultMappingPattern</param-name> <param-value>/SERVLET_NAME/*</param-value> </init-param> <init-param> <!-- This parameter defines the default context path that will be used to generate URLs --> <param-name>defaultContextPath</param-name> <param-value>/CONTEXT_NAME</param-value> or <param-value></param-value> if you are in a ROOT context </init-param> <init-param> <!-- This parameter defines the default servlet path that will be used to generate URLs --> <param-name>defaultServletPath</param-name> <param-value>/SERVLET_NAME</param-value> </init-param>for the JahiaConfigurationWizard :<servlet-name> JahiaConfigurationWizard </servlet-name> <servlet-class> org.jahia.bin.JahiaConfigurationWizard </servlet-class> <init-param> <param-name>default_locale</param-name> <param-value>en</param-value> </init-param> <init-param> <param-name>content_servlet_path</param-name> <param-value>/Jahia/</param-value> </init-param>to :<servlet-name> JahiaConfigurationWizard </servlet-name> <servlet-class> org.jahia.bin.JahiaConfigurationWizard </servlet-class> <init-param> <param-name>default_locale</param-name> <param-value>en</param-value> </init-param> <init-param> <param-name>content_servlet_path</param-name> <param-value>/SERVLET_NAME/</param-value> </init-param>for the JahiaAdministrationServlet :<servlet> <servlet-name> JahiaAdministration </servlet-name> <servlet-class> org.jahia.bin.JahiaAdministration </servlet-class> <init-param> <param-name>config_path</param-name> <param-value>/WEB-INF/etc/config/</param-value> </init-param> <init-param> <param-name>content_servlet_path</param-name> <param-value>/Jahia/</param-value> </init-param> </servlet>to :<servlet> <servlet-name> JahiaAdministration </servlet-name> <servlet-class> org.jahia.bin.JahiaAdministration </servlet-class> <init-param> <param-name>config_path</param-name> <param-value>/WEB-INF/etc/config/</param-value> </init-param> <init-param> <param-name>content_servlet_path</param-name> <param-value>/SERVLET_NAME/</param-value> </init-param> </servlet>in the servlet-mapping section :<servlet-mapping> <servlet-name>Jahia</servlet-name> <url-pattern>/Jahia/*</url-pattern> </servlet-mapping>becomes :<servlet-mapping> <servlet-name>Jahia</servlet-name> <url-pattern>/SERVLET_NAME/*</url-pattern> </servlet-mapping>Be careful in the above, the first Jahia (which is the servlet's internal name), must not be changed. -
In the tomcat/webapps/CONTEXT_NAME/WEB-INF/etc/struts/struts-config.xml
Replace occurrences of /Jahia with your SERVLET_NAME
in the following lines :
<global-forwards> <!-- Default Core Engine : display a Jahia Page with a template --> <forward name="coreEngine" path="/Jahia"/>to :<global-forwards> <!-- Default Core Engine : display a Jahia Page with a template --> <forward name="coreEngine" path="/SERVLET_NAME"/>and the following :<action path="/Jahia" type="org.jahia.bin.JahiaAction" scope="request" unknown="true"> </action>to :<action path="/SERVLET_NAME" type="org.jahia.bin.JahiaAction" scope="request" unknown="true"> </action> -
In the file tomcat/webapps/CONTEXT_NAME/html/startup/javascript_start.html,
Replace occurrences of /jahia with your /CONTEXT_NAME
in the line :
<p>If you are not automatically redirected to Jahia's welcome page, click <a href="/jahia/index.html" target="_top">here</a>to :<p>If you are not automatically redirected to Jahia's welcome page, click <a href="/CONTEXT_NAME/index.html" target="_top">here</a> -
In the file tomcat/webapps/CONTEXT_NAME/html/startup/loadingjahia.html,
in the line :
<meta http-equiv="Refresh" content="10;url=/jahia/">
to :<meta http-equiv="Refresh" content="10;url=/CONTEXT_NAME/">
or if you are using the ROOT context :<meta http-equiv="Refresh" content="10;url=/">
-
In the tomcat/webapps/CONTEXT_NAME/jsp/index.jsp, modify the following line :
response.sendRedirect(request.getContextPath() + "/Jahia/");toresponse.sendRedirect(request.getContextPath() + "/SERVLET_NAME/");Warning : if you are using our builds with pre-compiled templates, in order for the change in the JSP to be taken into account you will have to remove the pre-compiled mappings for index.jsp in the web.xml file. So remove the following lines from tomcat/webapps/CONTEXT_NAME/WEB-INF/web.xml :<servlet> <servlet-name>org.jahia.jsp.jahia.war.jsp.index_jsp</servlet-name> <servlet-class>org.jahia.jsp.jahia.war.jsp.index_jsp</servlet-class> </servlet>and<servlet-mapping> <servlet-name>org.jahia.jsp.jahia.war.jsp.index_jsp</servlet-name> <url-pattern>/jsp/index.jsp</url-pattern> </servlet-mapping> -
In bin/jahia.bat (or jahia.sh under Linux/Mac OS X/Solaris), change the following lines :
cd ..\tomcat\webapps\jahiato:cd ..\tomcat\webapps\CONTEXT_NAMEor if using the ROOT context :cd ..\tomcat\webapps\ROOTThen change the following line :
java -classpath "%CLASSPATH%;.\;.\WEB-INF\lib\jahia-5.0.0_JAHIA_BUILD_NUMBER.jar;.\WEB-INF\lib\log4j-1.2.15.jar" org.jahia.init.TomcatWaitwhere JAHIA_BUILD_NUMBER is your Jahia build number to :
java -classpath "%CLASSPATH%;.\;.\WEB-INF\lib\jahia-5.0.0_JAHIA_BUILD_NUMBER.jar;.\WEB-INF\lib\log4j-1.2.15.jar" org.jahia.init.TomcatWait http://localhost:8080/CONTEXT_NAME/html/startup/startjahia.htmlor if you are using the ROOT context, it should be :
java -classpath "%CLASSPATH%;.\;.\WEB-INF\lib\jahia-5.0.0_JAHIA_BUILD_NUMBER.jar;.\WEB-INF\lib\log4j-1.2.15.jar" org.jahia.init.TomcatWait http://localhost:8080/html/startup/startjahia.htmlAnd finally the following line must be changed :
start http://localhost:8080/jahia/html/startup/loadingjahia.html
to :
start http://localhost:8080/CONTEXT_NAME/html/startup/loadingjahia.html
or if you are using the ROOT context, it should be :
start http://localhost:8080/html/startup/loadingjahia.html
ESI configuration
-
In tomcat/webapps/ROOT/WEB-INF/config/data.xml :
<!-- the context path of the Jahia server on the remote server. If your remote Jahia server is accessible via a URL of the form http://myJahia:8080/jahia/Jahia/pid/1 the context path will be the '/jahia' in this case. So if you do change the default servlet context in Jahia, make sure you change it here also. --> <contextPath>/jahia</contextPath>modify the context path to /CONTEXT_NAME or nothing for the ROOT context so :<!-- the context path of the Jahia server on the remote server. If your remote Jahia server is accessible via a URL of the form http://myJahia:8080/jahia/Jahia/pid/1 the context path will be the '/jahia' in this case. So if you do change the default servlet context in Jahia, make sure you change it here also. --> <contextPath>/CONTEXT_NAME</contextPath>or for the ROOT context :<!-- the context path of the Jahia server on the remote server. If your remote Jahia server is accessible via a URL of the form http://myJahia:8080/jahia/Jahia/pid/1 the context path will be the '/jahia' in this case. So if you do change the default servlet context in Jahia, make sure you change it here also. --> <contextPath></contextPath>
Other references to Jahia (Servlet name)
-
In jsp/jahia/configuration_wizard/congratulations.jsp :
location.href = "<%= request.getContextPath() + "/Jahia" %>"This entry is hard coded, but it is assumed that users will install Jahia using the default context and servlet path, and will then change the installation using this guide. If you need Jahia to work "out of the box" even during configuration, you might run into issues, as this is not currently supported. - In jsp/jahia/javascript/zimbra/complexTree/ComplexTree.jsp : This file is used for testing only, so it won't have any incidence on Jahia's execution.
Setup for development
- In your $USER_HOME/build.properties file, set : maven.jahiawar.deploy.context.name=CONTEXT_NAME
- in the core/project.properties file, change the variable : webapp.name=CONTEXT_NAME
- Re-modify tomcat/webapps/WEB-INF/web.xml file each time as it is re-deployed after each hotdeploy:tomcat goal.
Url Rewriting without a front-end Apache Web Server
As an alternative to performing URL rewriting using the Apache Web Server with the mod_rewrite and mod_proxy plugins, we present here a method using a J2EE-compatible web filter, that is integrated with Jahia. For a complete user guide on how to use rules, we suggest you go their web page.
You might ask why we should configure URL rewriting at the application server level rather than using an Apache front-end web server? Apart from the added flexibility (the filter event supports custom rules implemented in Java), using an Apache front-end server adds an extra indirection processing, through the mod_jk layer. While this has the advantage of adding load-balancing, it also has the disadvantage of adding an extra communication layer before reaching the Jahia CMS server. Therefore, for installations that are very performance sensitive, but do not require a software load-balancer (because for example they use a hardware balancer such as an F5, http://www.f5.com/ ), using this filter still provides the URL rewriting possibility.
Activation in Jahia is done in the following way:
In tomcat/webapps/jahia/WEB-INF/web.xml
Just before :
<filter-mapping>
<filter-name>Set Header Filter</filter-name>
<url-pattern>/jsp/jahia/*</url-pattern>
</filter-mapping>
Uncomment: <filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<!-- set the amount of seconds the conf file will be checked for reload
can be a valid integer (0 denotes check every time,
-1 denotes no reload check, default -1) -->
<init-param>
<param-name>confReloadCheckInterval</param-name>
<param-value>20</param-value>
</init-param>
<!-- sets up log level (will be logged to context log)
can be: TRACE, DEBUG, INFO (default), WARN, ERROR, FATAL, log4j, commons,
sysout:{level} (i.e., sysout:DEBUG)
if you are having trouble using normal levels use sysout:DEBUG
(default WARN) -->
<init-param>
<param-name>logLevel</param-name>
<param-value>DEBUG</param-value>
</init-param>
</filter> Just before :
<!-- Display request URLs - Pattern-->
<filter-mapping>
<filter-name>ESIHeaderFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Uncomment :
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
In tomcat/webapps/jahia/WEB-INF/urlrewrite.xml
At the end ot this file, we have implemented some rules that act as a simple example with what can be done with this livrary in Jahia
However in this set of rules pages in edit/preview compare mode are not rewritten. These simple rules are urlKey friendly and work in multilingual websites
Of course you can add as many rules as you wish, bypassing some pages, etc.
It is relatively easy to expand on this example to configure more advanced rules. The Url Rewrite Filter is a powerful little tool that can do everything the mod_rewrite Apache plugin can do and a lot more ! And the nice thing is that it is Servlet API 2.3 compliant and that it can therefore be installed on any web application server such as Tomcat, Orion, Resin, WebLogic, Websphere; provided of course the web application server is recent enough to support this version of the Servlet API.
As the Url Rewrite Filter supports regular expressions, another useful tool to develop and test rules is an application such as RegexBuddy (for Windows), that lets you develop and test regular expressions. You can find this tool here : http://www.regexbuddy.com/
Known Issues
It should be noted also that Jahia installations that use the ESI cache server will have to move the Url Rewrite filter to the ESI cache server Tomcat installation, rather than installing it directly in Jahia. This works exactly the same way as we have described here, except that the configuration will have to happen in the ESI's web application context instead of Jahia's (specifically in the tomcat/ROOT directory by default).
Links that are contained in Bigtext do not get rewritten so you will still see a /pid/xxx when hovering the mouse over the bigtext link
Special care should also be taken when we are performing copy/paste operations on pages