A rewrite engine makes it possible to rewrite requests addressed to a web server internally or to forward them externally. For the Apache web server, the software module mod_rewrite does this job. Other web servers such as Microsoft IIS, Nginx, Lighttpd or Hiawatha web servers offer similar functions.
This functionality was created in order to be able to provide an addressing scheme to the outside world that is independent of internal factors, so that, for example, even if the file hierarchy is changed, the URLs remain valid. This is also referred to as permanent links.
The rewrite engines allow address redirection to be made dependent on additional conditions in addition to the requested URL, such as the referencing URL, the user-agent identifier, or the IP address of the requesting client. In this way, for example, forwarding or cloaking can be realized.
---

Sample Application of Rewrite Engine
Rewrite engines are often used to make resources accessible with dynamic URLs at alternate addresses.
The resource with the internal, technical address
1 | /b/index.php?title=pages |
can also be reached, for example, at the following address
1 | /blog/pages |
To the outside world, instead of dynamic, parameterized addresses, seemingly static addresses are used. This is useful because short, self-explanatory addresses are usually considered to be more readable, easier to remember, and generally more trustworthy. This is also referred to as clean URLs.
The implementation of the use case shown varies depending on the web server software used and the context. Typically, regular expressions are used to define a search pattern that is applied to a desired target pattern. The search pattern is the apparent static address. The target pattern is the internal or physical resource. The dynamic ranges, such as the article ID of an article from the search pattern, are usually transferred to the target pattern with the help of variables.
Below are some examples of the concrete implementation for the Apache module mod_rewrite, the web server nginx and the web server Lighttpd.
Apache/mod_rewrite
1 2 | RewriteEngine on RewriteRule ^/blog/(.*)$ /w/index.php?title=$1 |
nginx
1 2 3 | location /blog { rewrite ^/blog/(.*)$ /index.php?title=$1; } |
Lighttpd
1 2 3 | url.rewrite-once = ( "^/blog/(.*)$" => "/index.php?title=$1" ) |