Rewrite engine

from Wikipedia, the free encyclopedia

A rewrite engine (from English rewrite , "rewrite" and engine , "machine") makes it possible to internally rewrite queries directed to a web server or to forward them externally. For the Apache Web server , the completed software module mod_rewrite this task. 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 that is independent of internal factors so that, for example, the URLs remain valid even if the file hierarchy is changed . In this case, one also speaks of permanent links .

The rewrite engines allow address redirection to be made dependent on additional conditions in addition to the requested URL, for example on the referencing URL , the user agent ID or the IP address of the requesting client . In this way, for example, forwarding or cloaking can be implemented.

Sample application

Rewrite engines are often used to make resources accessible with dynamic URLs at alternative addresses.

The resource with the internal, technically required address

/w/index.php?title=Beispiel

can also be reached at the following address, for example

/wiki/Beispiel

To the outside world, apparently static addresses are used instead of dynamic, parameterized addresses. This is useful because short, self-explanatory addresses are usually classified as readable, easier to remember, and generally more trustworthy. In this case, one also speaks of 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 areas, for example the article ID of an article from the search pattern, are usually transferred to the target pattern with the help of variables.

The following are some examples of the specific implementation for the Apache module mod_rewrite , the web server nginx and the web server Lighttpd .

Apache / mod_rewrite

RewriteEngine on
RewriteRule ^/wiki/(.*)$ /w/index.php?title=$1

nginx

location /wiki {
   rewrite ^/wiki/(.*)$ /index.php?title=$1;
}

Lighttpd

url.rewrite-once = (
    "^/wiki/(.*)$" => "/index.php?title=$1"
)

The part of the regular expression marked in bold means that any character is written to the variable $1and thus applied to the target pattern.

Web links