Name
ScriptAliasMatch
Synopsis
ScriptAliasMatch regex directory_or_filename
Server config, virtual host
The supplied regular expression is matched against the URL; if it matches, the server will substitute any parenthesized matches into the given string and use them as a filename. For example, to activate the standard /cgi-bin, one might use:
ScriptAliasMatch ^/cgi-bin/(.*) /usr/local/apache/cgi-bin/$1
.*
is a regular expression like those in Perl that
match any character (.) any number of times (*). Here, this will be
the name of the file we want to execute. Putting it in parentheses
(.*)
stores the characters in the variable
$1
, which is then invoked:
/usr/local/apache/cgi-bin/$1.
You can start the matching further along. If all your script filenames start with the letters “BT,” you could write:
ScriptAliasMatch ^/cgi-bin/BT(.*) /usr/local/apache/cgi-bin/BT$1
If the visitor got here by following a link on the web page:
...<a href="/cgi-bin/BTmyscript/customer56/ice_cream">...
ScriptAliasMatch
will run
BTmyscript
. If it accesses
the environment variable PATH_INFO
(described in Chapter 14), it will
find /customer56/ice_cream
.
You can have as many of these useful directives as you like in your Config file to cover different situations. For more information on regular expressions, see Mastering Regular Expressions by Jeffrey Friedl (O’Reilly, 2002) or Programming Perl by Larry Wall, Jon Orwant, and Tom Christiansen (O’Reilly, 2001).
Get Apache: The Definitive Guide, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.