Short XWiki URLs
This tutorial shows how to tune your XWiki platform by replacing the default URL scheme with a shorter scheme.Application name
The /xwiki/ part of the URL is the application name. It identifies the application that should process the request, and it allows a container to host more than one application. To change it you must refer to your container's documentation and find how to map the context path of a web application. For example on Tomcat it's enough to simply deploy the XWiki webapp in the webapps directory, in a sub directory named after the application name you wish to use (e.g. webapps/myappname). A special case is when deploying XWiki as the ROOT application, which actually allows the application name part to be empty, so an URL can take the form server.com/bin/view/Space/Document. Achieving this again depends on the container, as there's no standard regarding the ROOT application. For example in Tomcat, with the default configuration, all it takes is to deploy the XWiki web application in webapps, in a sub directory named ROOT (i.e. webapps/ROOT). In Jetty, the default name is root. Refer to your container's documentation for more details.Struts action name
The third part, /view/, identifies the struts action that should process a request. So this tells what do we want to do with the document, /view/ it, /edit/ it or /delete/ it, for example. The XWiki platform allows this part to be missing, considering that the default action is to just display the document, so an URL like server.com/bin/Space/Document will work out of the box. Even more, the URL factory, the component that generates URLs, can be configured to skip this part when the action is /view/. To do this, in xwiki.cfg write:xwiki.showviewaction=0
Servlet mapping name
The second part is the hardest part to remove. It identifies the servlet that should process the page, which, for /bin/, is the Struts servlet. To get rid of /bin/, for the moment web.xml must be changed in a container-dependent way, so that the container's default servlet is configured to serve the existing directories, like skins, yui, tinymce and wikieditor. In Jetty, the container shipped with the XWiki installer, you will have to write something like:<servlet> <servlet-name>defaultSkins</servlet-name> <servlet-class>org.mortbay.jetty.servlet.Default</servlet-class> <init-param> <param-name>relativeResourceBase</param-name> <param-value>skins</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>defaultSkins</servlet-name> <url-pattern>/skins/*</url-pattern> </servlet-mapping>
<servlet-mapping> <servlet-name>action</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping>
xwiki.defaultactionpath=
Error Page
At the WEB-INF/web.xml, the location of the 404 error code needs to be changed accordingly. For example:<error-page> <error-code>404</error-code> <!--<location>/xwiki/bin/view/Main/DocumentDoesNotExist</location>--> <location>/bin/Main/DocumentDoesNotExist</location> </error-page>
Conclusion
After performing all these changes, you should be able to access documents with URLs like:- server.com/Space/Document
- server.com/Space/ (pointing to Space.WebHome)
- server.com/Document (pointing to Main.Document)
- server.com/ will show Main.WebHome, without any redirect.
on 2008/12/05 05:08