Web sites with dynamic content can 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/w/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 encodingthe 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
There are several benefits to using URL rewriting:
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.
There can, however be drawbacks as well; if a user wants to modify a URL to retrieve new data, URL rewriting 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=06&Month=04&Day=02
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.
URL Rewrite is available as an extension to Microsoft IIS.
Ruby on Rails has built-in URL rewriting via Routes.
Jakarta Servlet has extendable URL rewriting via the OCPsoft URLRewriteFilter and Tuckey UrlRewriteFilter.
Jakarta Server Faces has 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.
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 OKHTTP 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 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.
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, making it a useful feature of modern web frameworks.