Rewriting: applying the rewrite rule template

Once a host/domain specification  matches a rewrite rule, it is  rewritten using the template  part of the rule. The template specifies three things:



 a new username for the address, 

 a new host/domain specification for the address, and 

 the name of a system attached to an existing MTA channel (the   "routing system") to which messages to this address should    actually be sent. 



Template format is discussed in detail in Rewrite_rule_templates. As a quick overview, note that the most  common format for templates is  A%B@C,  where A is the new username,  B is the new host/domain specification,  and C is the routing system. And the format A@C  (which is an  abbreviation for A%C@C) is also commonly used.

Substitution stringsare allowed in the template. For instance, to mention some of the more commonly used substitution strings, any  occurrences of     in the template are replaced with the username from  the original address, any occurrences of     are replaced with the  portion of the host/domain specification that was not matched by the  rule, and any occurrences of     are replaced by the portion of the  host/domain specification that was matched by the rewrite rule. Summary of template substitutions and control sequences contains a summary of these and other substitution  strings which are presented in detail in   Rewrite rule template substitutions and control sequences.

As an example, suppose that the host/domain specification jdoe@domain.com has matched the rewrite rule domain.com      $U@DOMAIN.COM Then the template will produce the username jdoe, the host/domain specification DOMAIN.COM, and the routing system DOMAIN.COM. In a slightly more complicated example, assume that the host/domain specification has  matched the rewrite rule .com          $U%$H$D@TCP-DAEMON In this case, = jdoe,  = domain, and   = .com. The template produces the username jdoe, the host/domain specification domain.com, and  the routing system TCP-DAEMON.

See also:
 * Rewriting: scanning for a domain match
 * Rewrite rule templates
 * Ordinary rewriting templates
 * Rewrite rule template substitutions and control sequences
 * Rewrite username and subaddress substitutions
 * Rewrite host domain and IP literal substitutions
 * Application of rewrite rules to addresses