Skip to main content

  | मौसम…

411 समाचार
Public archive edition · Attributed source reporting with original dates · AI drafts are excluded

411 REFERENCE · Wikibooks

XRX/URL Rewriting

Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.

Motivation 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 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 The eXist native XML database has an Atom Publishing Protocol interface. You can use this to create new URL interfaces to existing XQueries. Example 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 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 An XForms application to manage Jetty rewrite URLS. References 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,1-56592-257-3 Excellent example of how Drupal handles URL rewrites with their PATH module Back: Content Routing fr:Apache/URL Rewriting