XRX/URL Rewriting

< XRX

Motivation

edit

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

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

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

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

http://example.com/exist/rest/db/apps/glossary/views/terms-changed.xq?days=N&project=P/


The URL rewrite might be:

http://example.com/terms/new/days=N/project=P/

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

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

An XForms application to manage Jetty rewrite URLS.

References

edit

Back: Content Routing