4.3. Script Directives

Apache has five directives defining CGI script alternatives.

4.3.1. ScriptAlias

ScriptAlias URLpath directory
Server config, virtual host

The ScriptAlias directive converts requests for URLs starting with URLpath to execution of the CGI program found in directory. In other words, an incoming URL like URLpath/fred causes the program stored in directory/fred to run, and its output is returned to the client. Note that directory must be an absolute path. We recommend that this path be outside your webspace.

A cute feature of ScriptAlias is that it can allow a CGI to pretend to be a directory. If someone submits the URL URLpath/fred/some/where/else, then directory/fred is run, and /some/where/else is passed to it in the PATH_INFO environment variable. This can be used for all sorts of things, but one is worth mentioning: many browsers and caches detect CGIs by the presence of a question mark in the URL, and refuse to cache them. This gives a way of fooling them into caching. Of course, you should be sure you want them cached (or use cache control headers to prevent it, if that was not what you had in mind).

4.3.2. ScriptAliasMatch

               ScriptAliasMatch regex directory
Server config, virtual host

This directive is equivalent to ScriptAlias but makes use of standard regular expressions instead of simple prefix matching. The supplied regular expression is matched against the URL; if it matches, the server will substitute any parenthesized matches into the given ...

Get Apache: The Definitive Guide, Second 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.