You want the URLs/URIs in your system to reflect the logical structure of a service, not the collection structure of your database.
Method 1: Use the Jetty Rewrite HandlerEdit
Use the Jetty Rewrite Handler that can be installed with the Jetty Server. The RewriteHandler uses an XML configuration file to store the rewrite patterns of a URI. This file can contain regular expressions that allow a single rule to be used rewrite a large number of URIs.
Method 2: Use an Atom interfaceEdit
The eXist native XML database has an Atom Publishing Protocol interface. You can use this to create new URL interfaces to existing XQueries.
Suppose you use XQuery to execute a report of all terms that have changed in the last N days for project P. Using an eXist XQuery the URL might be
The URL rewrite might be:
This makes the URL become a more stable application program interface and allows you to move the XQuery to another location in the eXist database and change parameter names without impacting your consumers, their bookmarks, or other systems that access this data through a REST interface.
Example Using Apache Mod RewriteEdit
The most popular way to implement URL rewriting is to use the Apache web server as a front end to your web application. This allows you to convert "dynamic" URLs into ones that appear to be "static", where there are no question marks or ampersands in the URL string and parameters are passed as though they were folders rather than key-value pairs.
Here is the code that would be added to the Apache configuration file:
Options +FollowSymLinks RewriteEngine on RewriteRule terms/new/days=(.*)/project=(.*)/ db/apps/glossary/views/terms-changed.xq?days=$1&project=$2
An XForms application to manage Jetty rewrite URLS.
- Wikipedia Article on Rewrite Engine
- Jetty Rewrite Handler
- Tool to help you learn how to write Apache rewrite rules
- Mastering Regular Expressions, Jeffrey E.F. Friedl, Nutshell Handbook Series, O'Reilly & Associates, Inc. 1997,ISBN 1-56592-257-3
- Excellent example of how Drupal handles URL rewrites with their PATH module