XRX/URL Rewriting

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Motivation[edit | edit source]

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 Handler[edit | edit source]

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 interface[edit | edit source]

The eXist native XML database has an Atom Publishing Protocol interface. You can use this to create new URL interfaces to existing XQueries.

Example[edit | edit source]

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 Rewrite[edit | edit source]

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

See also[edit | edit source]

An XForms application to manage Jetty rewrite URLS.

References[edit | edit source]

Back: Content Routing