Wiki source code of ShortURLs

Version 7.1 by Sergiu Dumitriu on 2007/12/22

Hide last authors
Vincent Massol 6.1 1 #startfloatingbox()
2 *Content*
3 #toc("" "" "")
4 #endfloatingbox()
5
Vincent Massol 5.1 6 1 Short XWiki URLs
maalej 1.1 7
Vincent Massol 5.1 8 This tutorial shows how to tune your XWiki platform by replacing the default URL scheme with a shorter scheme.
maalej 3.1 9
Vincent Massol 5.1 10 #info("A short URL is an URL without the xwiki/bin/view parts.")
maalej 2.1 11
Sergiu Dumitriu 4.1 12 1.1 Application name
maalej 1.1 13
Sergiu Dumitriu 6.2 14 The /xwiki/ part is the application name. It identifies the application that should process the request, and it allows a container to host more than one application. You can change this part to any other name, by renaming the xwiki directory and changing the <tt>dispay-name</tt> parameter in <tt>web.xml</tt>. 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 <tt>server.com/bin/view/Space/Document</tt>.
maalej 1.1 15
Sergiu Dumitriu 6.2 16 If you deploy XWiki as the ROOT app, don't forget to also change in <tt>WEB-INF/web.xml</tt> the <tt>display-name</tt> parameter to the empty string, like:
Sergiu Dumitriu 4.1 17 {code:xml}<display-name></display-name>{code}
maalej 1.1 18
Sergiu Dumitriu 6.2 19
Sergiu Dumitriu 4.1 20 1.1 Struts action name
maalej 1.1 21
Sergiu Dumitriu 4.1 22 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 <tt>server.com/bin/Space/Document</tt> will work out of the box.
maalej 1.1 23
Sergiu Dumitriu 4.1 24 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 <tt>xwiki.cfg</tt> write:
maalej 1.1 25
Sergiu Dumitriu 4.1 26 {code:none}xwiki.showviewaction=0{code}
27
28 1.1 Servlet mapping name
29
30 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 <tt>web.xml</tt> must be changed in a
31 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:
32
33 {code:xml}
34 <servlet>
35 <servlet-name>defaultSkins</servlet-name>
36 <servlet-class>org.mortbay.jetty.servlet.Default</servlet-class>
37 <init-param>
38 <param-name>relativeResourceBase</param-name>
39 <param-value>skins</param-value>
40 </init-param>
41 <load-on-startup>1</load-on-startup>
42 </servlet>
43 <servlet-mapping>
44 <servlet-name>defaultSkins</servlet-name>
45 <url-pattern>/skins/*</url-pattern>
46 </servlet-mapping>
47 {code}
48
Sergiu Dumitriu 7.1 49 In Tomcat, the default servlet does not accept a parameter for changing the resource base, so you will need to write another default servlet.
Sergiu Dumitriu 4.1 50
51 The second thing to do, is to copy the mapping for the Struts servlet to also be activated for /, like:
52 {code:xml}
53 <servlet-mapping>
54 <servlet-name>action</servlet-name>
55 <url-pattern>/*</url-pattern>
56 </servlet-mapping>
57 {code}
58 Be sure to leave the other mappings in place, so that /bin/ works, too.
59
60 And the last thing that must be changed is the default mapping used by the URL factory, by adding in <tt>xwiki.cfg</tt>:
61 {code:none}xwiki.defaultactionpath={code}
62
Vincent Massol 5.1 63 1.1 Conclusion
Sergiu Dumitriu 4.1 64
65 After performing all these changes, you should be able to access documents with URLs like:
66 * server.com/Space/Document
67 * server.com/Space/ (pointing to Space.WebHome)
68 * server.com/Document (pointing to Main.Document)
69 * server.com/ will show Main.WebHome, without any redirect.
70
Vincent Massol 5.1 71 As a bonus, these changes are backwards compatible, meaning that any currently working URL will also work with these changes performed, so you won't have any broken bookmarks.
72

Get Connected