Rewrite engine
Encyclopedia
A rewrite engine is software that modifies a web URL
Uniform Resource Locator
In computing, a uniform resource locator or universal resource locator is a specific character string that constitutes a reference to an Internet resource....

's appearance (URL rewriting). Rewritten URLs (sometimes known as short, fancy URLs, or search engine friendly - SEF) are used to provide shorter and more relevant-looking links to web pages. The technique adds a degree of separation between the files used to generate a web page and the URL that is presented to the World.

Usage

Websites with dynamic content
Dynamic web page
A dynamic web page is a kind of web page that has been prepared with fresh information , for each individual viewing. It is not static because it changes with the time , the user , the user interaction , the context A dynamic web page is a kind of web page that has been prepared with fresh...

 use URLs that generate pages from the server using query string
Query string
In World Wide Web, a query string is the part of a Uniform Resource Locator that contains data to be passed to web applications such as CGI programs....

 parameters. These are often rewritten to resemble URLs for static pages
Static web page
A static web page is a web page that is delivered to the user exactly as stored, in contrast to dynamic web pages which are generated by a web application....

 on a site with a subdirectory hierarchy. For example, the URL to a wiki
Wiki
A wiki is a website that allows the creation and editing of any number of interlinked web pages via a web browser using a simplified markup language or a WYSIWYG text editor. Wikis are typically powered by wiki software and are often used collaboratively by multiple users. Examples include...

 page might be:
http://example.com/wiki/index.php?title=Page_title
but can be rewritten as:
http://example.com/wiki/Page_title

A blog
Blog
A blog is a type of website or part of a website supposed to be updated with new content from time to time. Blogs are usually maintained by an individual with regular entries of commentary, descriptions of events, or other material such as graphics or video. Entries are commonly displayed in...

 might have a URL that encodes the dates of each entry:
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=19
It can be altered like this:
http://www.example.com/Blog/2006/12/19/
which also allows the user to change the URL to see all postings available in December, simply by removing the text encoding the day '19', as though navigating "up" a directory:

http://www.example.com/Blog/2006/12/

Benefits and drawbacks

There are several benefits to using a rewrite engine for URLs:
  • The links are "cleaner" and more descriptive, improving their "friendliness" to both users
    Usability
    Usability is the ease of use and learnability of a human-made object. The object of use can be a software application, website, book, tool, machine, process, or anything a human interacts with. A usability study may be conducted as a primary job function by a usability analyst or as a secondary job...

     and search engines
    Search engine optimization
    Search engine optimization is the process of improving the visibility of a website or a web page in search engines via the "natural" or un-paid search results...

    .
  • They prevent undesired "inline linking
    Inline linking
    Inline linking is the use of a linked object, often an image, from one site by a web page belonging to a second site...

    ", which can waste bandwidth
    Bandwidth (computing)
    In computer networking and computer science, bandwidth, network bandwidth, data bandwidth, or digital bandwidth is a measure of available or consumed data communication resources expressed in bits/second or multiples of it .Note that in textbooks on wireless communications, modem data transmission,...

    .
  • They hide the inner workings of a web site's address to visitors, which can prevent them from discovering query strings that could compromise the site.
  • The site can continue to use the same URLs even if the underlying technology used to serve them is changed (for example, switching to a new blogging engine).


There can, however be drawbacks as well; if a user wants to modify a URL to retrieve new data, the rewrite engine may hinder the construction of custom queries due to the lack of named variables. For example, it's difficult to determine the date from the following format:
http://www.example.com/Blog/12/10/2006/
In this case, the original query string was more useful, since the query variables indicated month and day:
http://www.example.com/Blog/Posts.php?Year=2006&Month=12&Day=10

Web frameworks

Many web frameworks include URL rewriting, either directly or through extension modules.
  • Apache HTTP Server
    Apache HTTP Server
    The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...

     has URL rewriting provided by the mod_rewrite module
  • URL Rewrite is available as an extension to Microsoft IIS
    Internet Information Services
    Internet Information Services – formerly called Internet Information Server – is a web server application and set of feature extension modules created by Microsoft for use with Microsoft Windows. It is the most used web server after Apache HTTP Server. IIS 7.5 supports HTTP, HTTPS,...

  • Ruby on Rails
    Ruby on Rails
    Ruby on Rails, often shortened to Rails or RoR, is an open source web application framework for the Ruby programming language.-History:...

     has built-in URL rewriting via Routes
  • Java
    Java
    Java is an island of Indonesia. With a population of 135 million , it is the world's most populous island, and one of the most densely populated regions in the world. It is home to 60% of Indonesia's population. The Indonesian capital city, Jakarta, is in west Java...

    , and Servlet/Java EE have extendable URL rewriting via the OCPsoft URL Rewrite extension
  • Java Server Faces, Java EE, and Servlet have simplified URL rewriting via the PrettyFaces: URL rewriting extension
  • Django uses a regular-expressions
    Regular expression
    In computing, a regular expression provides a concise and flexible means for "matching" strings of text, such as particular characters, words, or patterns of characters. Abbreviations for "regular expression" include "regex" and "regexp"...

     based system. Note that this is not strictly URL rewriting since there is no script to 'rewrite' to, nor even a directory structure.
  • Java
    Java
    Java is an island of Indonesia. With a population of 135 million , it is the world's most populous island, and one of the most densely populated regions in the world. It is home to 60% of Indonesia's population. The Indonesian capital city, Jakarta, is in west Java...

     Stripes Framework
    Stripes (framework)
    -External links:********...

     has had integrated functionality since version 1.5
  • Many Perl frameworks, such as Mojolicious
    Mojolicious
    Mojolicious is a real-time web application framework, written by Sebastian Riedel, creator of the web application framework Catalyst. Licensed as free software under the Artistic License v 2.0, It is written in Perl, and is designed for use in both simple and complex web applications, based on...

     and Catalyst
    Catalyst (software)
    Catalyst is an open source web application framework written in Perl, that closely follows the model–view–controller architecture, and supports a number of experimental web patterns. It is written using Moose, a modern object system for Perl...

    , have this feature
  • Codeigniter has URL rewriting provided.
  • lighttpd
    Lighttpd
    lighttpd is an open-source web server more optimized for speed-critical environments than common products while remaining standards-compliant, secure and flexible...

     has mod_rewrite module.


From a software development
Software development
Software development is the development of a software product...

 perspective, URL rewriting can aid in code modularization and control flow
Control flow
In computer science, control flow refers to the order in which the individual statements, instructions, or function calls of an imperative or a declarative program are executed or evaluated....

, making it a useful feature of modern web frameworks.

See also

  • htaccess
  • Apache HTTP Server
    Apache HTTP Server
    The Apache HTTP Server, commonly referred to as Apache , is web server software notable for playing a key role in the initial growth of the World Wide Web. In 2009 it became the first web server software to surpass the 100 million website milestone...

  • Content negotiation
    Content negotiation
    Content negotiation is a mechanism defined in the HTTP specification that makes it possible to serve different versions of a document at the same URI, so that user agents can specify which version fit their capabilities the best...

  • HTTP
  • Internet Information Server
  • Permalink
    Permalink
    A permalink is a URL that points to a specific blog or forum entry after it has passed from the front page to the archives. Because a permalink remains unchanged indefinitely, it is less susceptible to link rot. Most modern weblogging and content-syndication software systems support such links...

  • Zeus Web Server
    Zeus Web Server
    Zeus Web Server is a proprietary web server for Unix and Unix-like platforms . Support for AIX, Tru64, and Mac OS X was dropped on 10 June 2008....

  • Clean URL

Apache

  • Apache mod_rewrite
  • mod_alias Simpler Apache module allowing for manipulation and control of URLs as requests arrive at the server.
  • Rewrite rule tester This tool lets you write and test your rewrite rules for Apache's mod_rewrite on-the-fly.
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK