Rewrite engine
| This article relies on references to primary sources or sources affiliated with the subject, rather than references from independent authors and third-party publications. Please add citations from reliable sources. (January 2011) |
|
|
This article's use of external links may not follow Wikipedia's policies or guidelines. Please improve this article by removing excessive or inappropriate external links, and converting useful links where appropriate into footnote references. (January 2011) |
A rewrite engine is software located in a Web application framework running on a Web server that modifies a web URL's appearance. This modification is called 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 outside world.
Contents |
[edit] Usage
Websites 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/
[edit] Benefits and drawbacks
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.
- 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
[edit] Web frameworks
Many web frameworks include URL rewriting, either directly or through extension modules.
- Apache HTTP Server has URL rewriting provided by the mod_rewrite module [2]
- URL Rewrite is available as an extension to Microsoft IIS [3]
- Ruby on Rails has built-in URL rewriting via Routes[4]
- Java, and Servlet/Java EE have extendable URL rewriting via the OCPsoft URL Rewrite extension and UrlRewriteFilter
- Java Server Faces, Java EE, and Servlet have simplified URL rewriting via the PrettyFaces: URL rewriting extension
- Django uses a regular-expressions based system. Note that this is not strictly URL rewriting since there is no script to 'rewrite' to, nor even a directory structure; but it provides the full flexibility of URL rewriting.[5]
- Java Stripes Framework has had integrated functionality since version 1.5[6]
- Many Perl frameworks, such as Mojolicious and Catalyst, have this feature[7]
- Codeigniter has URL rewriting provided.
- lighttpd has mod_rewrite module.[8]
- Hiawatha HTTP server has URL Toolkit which support URL rewriting.[9]
- Cherokee HTTP server supports regular expressions of URL rewriting and redirections.
From a software development perspective, URL rewriting can aid in code modularization and control flow,[10] making it a useful feature of modern web frameworks.
[edit] See also
- htaccess
- Apache HTTP Server
- Content negotiation
- HTTP
- Internet Information Server
- Permalink
- Zeus Web Server
- Clean URL
[edit] Notes
- ^ 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.
- ^ mod_rewrite documentation
- ^ URL Rewrite extension for Microsoft IIS
- ^ Routes
- ^ Django URLconf
- ^ clean urls in Stripes 1.5
- ^ [1]
- ^ [2]
- ^ URL TOOLKIT part of Hiawatha webserver's manual
- ^ DocForge: Clean URL
[edit] External links
[edit] 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.
- Arithmetic fun with mod_rewrite Describes how to extend mod_rewrite's functionality with a plug-in module.