Recently, AppFuse user Charlse Li sent me an e-mail with a "PostfixURLConstructor" class designed to pretty up JSPWiki's URL. With the patch he sent, I was able to change URLs from /wiki/Wiki.jsp?page=AppFuse to /wiki/AppFuse.html. Applying the patch was quite easy, but maintaining backwards compatibility and security required a little more work. Below are the steps I went through to get everything working properly:
- Download postfixurlconstructor.zip and extract to your hard-drive. Copy the "com" directory to your wiki/WEB-INF/classes directory.
- Change the <url-pattern> of the WikiServlet in web.xml from /wiki/* to *.html.
- Add the following two lines to your WEB-INF/jspwiki.properties file:
jspwiki.urlConstructor = PostfixURLConstructor
jspwiki.PostfixURLConstructor.postfix = .html
This is all you need to do to change the default URL schema. However, if you're like me and you've had a JSPWiki instance setup for awhile, you'll need to maintain backwards-compatibility. I wanted to make sure the old URLs mapped to the new ones. In addition, the "edit URL" changed from Edit.jsp?page=PageName to pageName.html?do=Edit. Since web.xml and <security-constraint> can't contain regular expressions, I used the ultra-cool UrlRewriteFilter to solve both issues. Here's the steps I went through to configure it properly:
- Download UrlRewriteFilter 2.5.1 and extract the JAR to your WEB-INF/lib directory.
- Change your web.xml to use a 2.3 DTD instead of a 2.2 DTD and add the filter and filter-mapping to web.xml.
- Create a WEB-INF/urlrewrite.xml file with the following contents:
<?xml version="1.0" encoding="utf-8"?> <!DOCENGINE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.5//EN" "http://tuckey.org/res/dtds/urlrewrite2.5.dtd"> <urlrewrite> <rule> <from>^/Wiki.jsp\?page=(.*)$</from> <to type="redirect">$1.html</to> </rule> <rule> <from>^/(.*).html\?do=Edit$</from> <to type="redirect">Edit.jsp?page=$1</to> </rule> </urlrewrite>
That's it - restart your server and you should be good to go. Thanks for the patch and instructions Charlse!
Update: There does seem to be a couple of issues. The 1st is that none of the attachments are resolving correctly (example). The 2nd that when I try to edit a page, it always shows up with the Main page's text. I'm not going to back out the change just yet, but I will if I can't fix it in the next several hours.
Update 2: I ended up backing out this change, but left in a forward from *.html to Wiki.jsp?page=$1 so all URLs in this post should still work. The "not being able to edit" was the major reason I rolled back to the old URL schema. The attachment issue seems to be related to my browser's cache. Clearing it fixed the problem.