||It has been suggested that this article be merged into Semantic URL. (Discuss) Proposed since April 2012.|
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.
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:
but can be rewritten as:
A blog might have a URL that encodes the dates of each entry:
It can be altered like this:
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:
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:
Benefits and drawbacks
||This section possibly contains original research. (April 2013)|
There are several benefits to using a rewrite engine for URLs:
- 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:
In this case, the original query string was more useful, since the query variables indicated month and day:
Many web frameworks include URL rewriting, either directly or through extension modules.
- Apache HTTP Server has URL rewriting provided by the mod_rewrite module.
- URL Rewrite is available as an extension to Microsoft IIS.
- Ruby on Rails has built-in URL rewriting via Routes.
- Java, and Servlet/Java EE have extendable URL rewriting via the OCPsoft URLRewriteFilter and Tuckey UrlRewriteFilter.
- Java Server Faces, Java EE, and Servlet have simplified URL rewriting via the PrettyFaces: URLRewriteFilter.
- Django uses a regular-expressions based system. 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.
- Java Stripes Framework has had integrated functionality since version 1.5.
- Many Perl frameworks, such as Mojolicious and Catalyst, have this feature.
- CodeIgniter has URL rewriting provided.
- lighttpd has a mod_rewrite module.
- nginx has a rewrite module. Not only can it be used to manipulate URLs in various degrees for both internal and HTTP 301/302 status code redirection, but even 200 OK HTTP response message body generation is also possible with the return directive, making it viable to create rather advanced deterministic URL shortening services not limited to direct HTTP status code redirects. As an example, a multi-link multi-variable page generation from a URI like /f101,n61,o56,d/ifconfig is possible, where multiple individual parts like f101 get expanded with the help of regular expressions into variables to signify FreeBSD 10.1-RELEASE and so forth, and the generated page has links to multiple unique external URLs all at once, all done through internal variables and multiple location, rewrite and return directives.
- Hiawatha HTTP server has a URL Toolkit which supports URL rewriting.
- Cherokee HTTP server supports regular expressions of URL rewriting and redirections.
- Application Delivery Controller
- aiScaler Traffic Manager
- Apache HTTP Server
- Content negotiation
- Internet Information Server
- Zeus Web Server
- Semantic URL
- 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
- "Rails Routing from the Outside In". "Ruby on Rails. Retrieved 25 April 2014.
- Django URLconf
- clean urls in Stripes 1.5
- Guides - Mojolicious guide to the galaxy. Mojolicious. Retrieved on 2013-09-08.
- Docs ModRewrite - Lighttpd - lighty labs. Redmine.lighttpd.net. Retrieved on 2013-09-08.
- "ngx_http_rewrite_module - rewrite". nginx.org. Retrieved 25 December 2014.
- Murenin, Constantine A. (18 February 2013). "A dynamic web-site written wholly in nginx.conf? Introducing mdoc.su!". email@example.com mailing list. http://mailman.nginx.org/pipermail/nginx/2013-February/037592.html. Retrieved 24 December 2014.
- Murenin, Constantine A. (23 February 2013). "mdoc.su — Short manual page URLs for FreeBSD, OpenBSD, NetBSD and DragonFly BSD". Retrieved 25 December 2014.
- Murenin, Constantine A. (23 February 2013). "mdoc.su.nginx.conf". Retrieved 25 December 2014.
- URL TOOLKIT part of Hiawatha webserver's manual
- "Clean URL". DocForge. Retrieved 25 April 2014.
- Apache mod_rewrite
- mod_alias Simpler Apache module allowing for manipulation and control of URLs as requests arrive at the server.
- Arithmetic fun with mod_rewrite Describes how to extend mod_rewrite's functionality with a plug-in module.
- A thorough discussion of using the Apache rewrite engine to speed page-loading, running scripts, as well as the long-process effect. Contains usable code.