Previous Topic

Next Topic

Book Contents

Book Index

RegEx Rewrites

The regex rewrite is in fact much simpler as there are solid rules of usage. You always work with URIs and the result is always an URI or URL for redirect.

Source is a regex match pattern and Destination is a regex replace pattern. In the destination you can also specify flags.

The whole concept is based on mod_rewrite module for Apache and uses the same syntax.

^/data/(.*) -> http://server/$1 [R]

http://myserver/data/other/?script=value -> http://server/other/?script=value

This would take the string after data, redirect to a different server, but with the selected parameters in place.

So you can see you can do some tricks with it. Every () in the regex search pattern can be then used as a variable starting with "$" and index "n":

$1 $2 $3 etc.

You can create even more sophisticated rewrites such as:

^/test/(.*)/(.*)$ -> /scripts/$1?value=$2

^/data/(.*)/\?(.*) -> /$1/script.asp?value=$2

This would not do a redirect but a simple internal URI replace. It works even with URL variables and there are no boundaries at all.

If you wish to continue with next rewrite specify the flags without [L].

^/data/(.*)/\?(.*) /$1/script.asp?value=$2 []

Also there is a special destination "-" which means not to replace anything. It might come handy sometimes.

And that's it. The rest is up to admins- look for mod_rewrite syntax for more details.

See Also

Re-Write Tutorial

Differences

Directory Aliases - Absolute Path

Directory Aliases - Relative Path

Non RegEx Rewrites

Flags

Server Variables