Rewrite engine

From Wikipedia, the free encyclopedia
Jump to: navigation, search
In Wikipedia and other MediaWiki sites, see MediaWiki Manual:Short URL.

A rewrite engine is software located in a Web application framework running on a Web server that modifies a web URL's appearance. Many framework users have come to refer to this feature as a "Router". This modification is called URL rewriting. Rewritten URLs (sometimes known as short, pretty or fancy URLs, search engine friendly - SEF URLs, or slugs) are used to provide shorter and more relevant-looking links to web pages. The technique adds a layer of abstraction between the files used to generate a web page and the URL that is presented to the outside world.

Usage[edit]

Web sites with dynamic content use URLs that generate pages from the server using query string parameters. These are often rewritten to resemble URLs for static pages on a site with a subdirectory hierarchy. For example, the URL to a wiki 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 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/

A site can pass specialized terms from the url to its search engine as a search term. This would allow users to search directly from their browser. For example, the URL as entered into the browser's location bar:

http://example.com/search term

Will be urlencoded by the browser before it makes the http request. The server could rewrite this to:

http://example.com/search.php?q=search%20term

Benefits and drawbacks[edit]

There are several benefits to using a rewrite engine for URLs:[1]

  • The links are "cleaner" and more descriptive, improving their "friendliness" to both users and search engines.
  • They prevent undesired "inline linking", which can waste bandwidth.
  • 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 may be difficult to determine the date from the following format:

http://www.example.com/Blog/06/04/02/

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=04&Day=02

Web frameworks[edit]

Many web frameworks include URL rewriting, either directly or through extension modules.

From a software development perspective, URL rewriting can aid in code modularization and control flow,[11] making it a useful feature of modern web frameworks.

See also[edit]

Notes[edit]

  1. ^ Many of these only apply to HTTP servers whose default behavior is to map URLs to filesystem entities (i.e. files and directories); certain environments, such as many HTTP application server platforms, make this irrelevant.
  2. ^ mod_rewrite documentation
  3. ^ URL Rewrite extension for Microsoft IIS
  4. ^ "Rails Routing from the Outside In". "Ruby on Rails. Retrieved 25 April 2014. 
  5. ^ Django URLconf
  6. ^ clean urls in Stripes 1.5
  7. ^ Guides - Mojolicious guide to the galaxy. Mojolicious. Retrieved on 2013-09-08.
  8. ^ Docs ModRewrite - Lighttpd - lighty labs. Redmine.lighttpd.net. Retrieved on 2013-09-08.
  9. ^ HttpRewriteModule. Wiki.nginx.org (2013-08-23). Retrieved on 2013-09-08.
  10. ^ URL TOOLKIT part of Hiawatha webserver's manual
  11. ^ "Clean URL". DocForge. Retrieved 25 April 2014. 

External links[edit]

Apache[edit]