akosut 97/07/07 21:45:31
Modified: htdocs/manual new_features_1_3.html
htdocs/manual/mod core.html directives.html mod_alias.html
src CHANGES http_core.c mod_alias.c
Log:
Enable regex support in mod_alias with AliasMatch, ScriptAliasMatch and
RedirectMatch directives.
New syntax for regex support in http_core: <DirectoryMatch>,
<FilesMatch>, <LocationMatch> sections.
Revision Changes Path
1.6 +16 -0 apache/htdocs/manual/new_features_1_3.html
Index: new_features_1_3.html
===================================================================
RCS file: /export/home/cvs/apache/htdocs/manual/new_features_1_3.html,v
retrieving revision 1.5
retrieving revision 1.6
diff -c -C3 -r1.5 -r1.6
*** new_features_1_3.html 1997/07/08 02:04:36 1.5
--- new_features_1_3.html 1997/07/08 04:45:22 1.6
***************
*** 40,45 ****
--- 40,61 ----
Windows gives Apache the ability to run on a large number of web
servers it was not previously able to.
</P>
+
+ <li><b><a href="mod/mod_alias.html">Regular Expression support for Alias
+ and Redirect</a></b>
+ <p>
+ New <code><a href="mod/mod_alias.html#aliasmatch">AliasMatch</a></code>,
+ <code><a
+ href="mod/mod_alias.html#scriptaliasmatch">ScriptAliasMatch</a></code>, and
+ <code><a
+ href="mod/mod_alias.html#redirectmatch">RedirectMatch</a></code>
+ directives allow for the use of regular expression matching.
+ <p>Additionally, new
+ <code><a
href="mod_core.html#directorymatch"><DirectoryMatch></a></code>,
+ <code><a
href="mod_core.html#locationmatch"><LocationMatch></a></code>,
+ and <code><a href="mod_core.html#filesmatch"><FilesMatch></a></code>
+ sections provide a new syntax for regular expression sectioning.</p>
+
</LI>
<LI><STRONG>Support for Directory Icon Sizing</STRONG>
<P>
1.64 +74 -3 apache/htdocs/manual/mod/core.html
Index: core.html
===================================================================
RCS file: /export/home/cvs/apache/htdocs/manual/mod/core.html,v
retrieving revision 1.63
retrieving revision 1.64
diff -c -C3 -r1.63 -r1.64
*** core.html 1997/07/08 02:04:38 1.63
--- core.html 1997/07/08 04:45:23 1.64
***************
*** 31,40 ****
--- 31,42 ----
<li><A HREF="#clearmodulelist">ClearModuleList</A>
<li><A HREF="#defaulttype">DefaultType</A>
<li><A HREF="#directory"><Directory></A>
+ <li><A HREF="#directorymatch"><DirectoryMatch></A>
<li><A HREF="#documentroot">DocumentRoot</A>
<li><A HREF="#errordocument">ErrorDocument</A>
<li><A HREF="#errorlog">ErrorLog</A>
<li><A HREF="#files"><Files></A>
+ <li><A HREF="#filesmatch"><FilesMatch></A>
<li><A HREF="#group">Group</A>
<li><A HREF="#hostnamelookups">HostNameLookups</A>
<li><A HREF="#identitycheck">IdentityCheck</A>
***************
*** 45,50 ****
--- 47,53 ----
<li><A HREF="#listen">Listen</A>
<li><A HREF="#listenbacklog">ListenBacklog</A>
<li><A HREF="#location"><Location></A>
+ <li><A HREF="#locationmatch"><LocationMatch></A>
<li><A HREF="#lockfile">LockFile</A>
<li><A HREF="#maxclients">MaxClients</A>
<li><A HREF="#maxkeepaliverequests">MaxKeepAliveRequests</a>
***************
*** 305,311 ****
<Directory ~ "^/www/.*/[0-9]{3}">
</pre>
! would match directories in /www/ that consisted of three numbers.<p>
<p>If multiple directory sections match the directory (or its parents)
containing
a document, then the directives are applied in the order of shortest match
--- 308,316 ----
<Directory ~ "^/www/.*/[0-9]{3}">
</pre>
! would match directories in /www/ that consisted of three numbers. In
! Apache 1.3 and later, it is reccomended to use
! <a href="#directorymatch"><DirectoryMatch></a> instead.<p>
<p>If multiple directory sections match the directory (or its parents)
containing
a document, then the directives are applied in the order of shortest match
***************
*** 357,362 ****
--- 362,387 ----
nest, and cannot appear in a <A HREF="#limit"><Limit></A> section.
<p><hr>
+ <h2><A name="directorymatch"><DirectoryMatch></A></h2>
+ <strong>Syntax:</strong> <DirectoryMatch <em>regex</em>> ...
</DirectoryMatch> <br>
+ <strong>Context:</strong> server config, virtual host<br>
+ <strong>Status:</strong> Core.<br>
+ <strong>Compatibility:</strong> Available in Apache 1.3 and later
+
+ <p><DirectoryMatch> and </DirectoryMatch> are used to enclose a
group of
+ directives which will apply only to the named directory and sub-directories
+ of that directory, the same as <a
+ href="#directory"><Directory></a>. However, it takes as an
+ argument a regular expression. For example:</p>
+
+ <pre>
+ <DirectoryMatch "^/www/.*/[0-9]{3}">
+ </pre>
+
+ <p>would match directories in /www/ that consisted of three numbers.</p>
+
+ <hr>
+
<h2><A NAME="documentroot">DocumentRoot directive</A></h2>
<!--%plaintext <?INDEX {\tt DocumentRoot} directive> -->
<strong>Syntax:</strong> DocumentRoot <em>directory-filename</em><br>
***************
*** 478,484 ****
<Files ~ "\.(gif|jpe?g|png)$">
</pre>
! would match most common Internet graphics formats.
<p>Note that unlike <a
href="#directory"><code><Directory></code></a> and <a
--- 503,511 ----
<Files ~ "\.(gif|jpe?g|png)$">
</pre>
! would match most common Internet graphics formats. In Apache 1.3 and
! later, <a href="#filesmatch"><FilesMatch></a> is perferred,
! however.
<p>Note that unlike <a
href="#directory"><code><Directory></code></a> and <a
***************
*** 491,496 ****
--- 518,543 ----
<p> <hr>
+ <h2><A name="filesmatch"><FilesMatch></A></h2>
+ <strong>Syntax:</strong> <FilesMatch <em>regex</em>>
+ ... </Files><br>
+ <strong>Context:</strong> server config, virtual host, htaccess<br>
+ <strong>Status:</strong> core<br>
+ <strong>Compatibility:</strong> only available in Apache
+ 1.3 and above.<p>
+
+ <p>The <FilesMatch> directive provides for access control by
+ filename, just as the <a href="#files"><Files></a> directive
+ does. However, it accepts a regular expression. For example:</p>
+
+ <pre>
+ <FilesMatch "\.(gif|jpe?g|png)$">
+ </pre>
+
+ <p>would match most common Internet graphics formats.</p>
+
+ <hr>
+
<h2><A name="group">Group directive</A></h2>
<!--%plaintext <?INDEX {\tt Group} directive> -->
<strong>Syntax:</strong> Group <em>unix-group</em><br>
***************
*** 732,738 ****
</pre>
<p>would match URLs that contained the substring "/extra/data" or
! "/special/data".</p>
<p>The <code>Location</code> functionality is especially useful when
combined with the <code><a
--- 779,786 ----
</pre>
<p>would match URLs that contained the substring "/extra/data" or
! "/special/data". However, in Apache 1.3 and above, use of <a
! href="#locationmatch"><LocationMatch></a> is perferred.</p>
<p>The <code>Location</code> functionality is especially useful when
combined with the <code><a
***************
*** 747,752 ****
--- 795,823 ----
allow from .foo.com
</Location>
</pre>
+ <hr>
+
+ <h2><a name="locationmatch"><LocationMatch></a></h2>
+
+ <strong>Syntax:</strong> <LocationMatch <em>regex</em>>
+ ... </LocationMatch><br>
+ <strong>Context:</strong> server config, virtual host<br>
+ <strong>Status:</strong> core<br>
+ <strong>Compatibility:</strong> Location is only available in Apache
+ 1.3 and later.<p>
+
+ <p>The <LocationMatch> directive provides for access control by
+ URL, in an identical manner to <a
+ href="#location"><Location></a>. However, it takes a regular
+ expression as an argument instead of a simple string. For example:</p>
+
+ <pre>
+ <LocationMatch "/(extra|special)/data">
+ </pre>
+
+ <p>would match URLs that contained the substring "/extra/data" or
+ "/special/data".</p>
+
<hr>
<H2><A NAME="lockfile">LockFile directive</A></H2>
1.25 +6 -0 apache/htdocs/manual/mod/directives.html
Index: directives.html
===================================================================
RCS file: /export/home/cvs/apache/htdocs/manual/mod/directives.html,v
retrieving revision 1.24
retrieving revision 1.25
diff -c -C3 -r1.24 -r1.25
*** directives.html 1997/07/07 18:18:39 1.24
--- directives.html 1997/07/08 04:45:24 1.25
***************
*** 33,38 ****
--- 33,39 ----
<li><A HREF="mod_mime.html#addtype">AddType</A>
<li><A HREF="mod_log_agent.html#agentlog">AgentLog</A>
<li><A HREF="mod_alias.html#alias">Alias</A>
+ <li><A HREF="mod_alias.html#aliasmatch">AliasMatch</A>
<li><A HREF="mod_access.html#allow">allow</A>
<li><A HREF="core.html#allowoverride">AllowOverride</A>
<li><A HREF="mod_auth_anon.html#anonymous">Anonymous</A>
***************
*** 76,81 ****
--- 77,83 ----
<li><A HREF="core.html#defaulttype">DefaultType</A>
<li><A HREF="mod_access.html#deny">deny</A>
<li><A HREF="core.html#directory"><Directory></A>
+ <li><A HREF="core.html#directorymatch"><DirectoryMatch></A>
<li><A HREF="mod_dir.html#directoryindex">DirectoryIndex</A>
<li><A HREF="core.html#documentroot">DocumentRoot</A>
<li><A HREF="core.html#errordocument">ErrorDocument</A>
***************
*** 86,91 ****
--- 88,94 ----
<li><A HREF="mod_expires.html#expiresdefault">ExpiresDefault</A>
<li><A HREF="mod_dir.html#fancyindexing">FancyIndexing</A>
<li><A HREF="core.html#files"><Files></A>
+ <li><A HREF="core.html#filesmatch"><FilesMatch></A>
<li><A HREF="mod_mime.html#forcetype">ForceType</A>
<li><A HREF="core.html#group">Group</A>
<li><A HREF="mod_headers.html#header">Header</A>
***************
*** 107,112 ****
--- 110,116 ----
<li><A HREF="mod_dld.html#loadfile">LoadFile</A>
<li><A HREF="mod_dld.html#loadmodule">LoadModule</A>
<li><A HREF="core.html#location"><Location></A>
+ <li><A HREF="core.html#locationmatch"><LocationMatch></A>
<li><A HREF="core.html#lockfile">LockFile</A>
<li><A HREF="mod_log_config.html#logformat">LogFormat</A>
<li><A HREF="core.html#maxclients">MaxClients</A>
***************
*** 129,134 ****
--- 133,139 ----
<li><A HREF="mod_proxy.html#proxyrequests">ProxyRequests</A>
<li><A HREF="mod_dir.html#readmename">ReadmeName</A>
<li><A HREF="mod_alias.html#redirect">Redirect</A>
+ <li><A HREF="mod_alias.html#redirectmatch">RedirectMatch</A>
<li><A HREF="mod_alias.html#redirectperm">RedirectPermanent</A>
<li><A HREF="mod_alias.html#redirecttemp">RedirectTemp</A>
<li><A HREF="mod_log_referer.html#refererignore">RefererIgnore</A>
***************
*** 150,155 ****
--- 155,161 ----
<li><A HREF="core.html#scoreboardfile">ScoreBoardFile</A>
<li><A HREF="mod_actions.html#script">Script</A>
<li><A HREF="mod_alias.html#scriptalias">ScriptAlias</A>
+ <li><A HREF="mod_alias.html#scriptaliasmatch">ScriptAliasMatch</A>
<li><A HREF="mod_cgi.html#scriptlog">ScriptLog</A>
<li><A HREF="mod_cgi.html#scriptlogbuffer">ScriptLogBuffer</A>
<li><A HREF="mod_cgi.html#scriptloglength">ScriptLogLength</A>
1.12 +70 -0 apache/htdocs/manual/mod/mod_alias.html
Index: mod_alias.html
===================================================================
RCS file: /export/home/cvs/apache/htdocs/manual/mod/mod_alias.html,v
retrieving revision 1.11
retrieving revision 1.12
diff -c -C3 -r1.11 -r1.12
*** mod_alias.html 1997/07/06 17:19:15 1.11
--- mod_alias.html 1997/07/08 04:45:24 1.12
***************
*** 24,33 ****
--- 24,36 ----
<H2>Directives</H2>
<UL>
<li><A HREF="#alias">Alias</A>
+ <li><A HREF="#aliasmatch">AliasMatch</A>
<li><A HREF="#redirect">Redirect</A>
+ <li><A HREF="#redirectmatch">RedirectMatch</A>
<li><A HREF="#redirecttemp">RedirectTemp</A>
<li><A HREF="#redirectperm">RedirectPermanent</A>
<li><A HREF="#scriptalias">ScriptAlias</A>
+ <li><A HREF="#scriptaliasmatch">ScriptAliasMatch</A>
</UL>
<hr>
***************
*** 64,69 ****
--- 67,94 ----
</p>
<hr>
+ <h2><A name="aliasmatch">AliasMatch</A></h2>
+ <P>
+ <strong>Syntax:</strong> AliasMatch <em>regex directory-filename</em><br>
+ <Strong>Context:</strong> server config, virtual host<br>
+ <strong>Status:</strong> Base<br>
+ <strong>Module:</strong> mod_alias<br>
+ <strong>Compatibility:</strong> Available in Apache 1.3 and later
+ </P>
+
+ <p>This directive is equivilent to <a href="#alias">Alias</a>, but
+ makes use of standard regular expressions, instead of simple prefix
+ matching. The supplied regular expression is matched against the URL,
+ and if it matches, the server will substitute any parenthesized
+ matches into the given string and use it as a filename. For example,
+ to activate the <code>/icons</code> directory, one might use:
+ <pre>
+ AliasMatch ^/icons(.*) /usr/local/etc/httpd/icons$1
+ </pre>
+ </p>
+
+ <hr>
+
<h2><A name="redirect">Redirect directive</A></h2>
<P>
<!--%plaintext <?INDEX {\tt Redirect} directive> -->
***************
*** 128,133 ****
--- 153,181 ----
</P>
<HR>
+ <h2><A name="redirectmatch">RedirectMatch</A></h2>
+ <P>
+ <strong>Syntax:</strong> RedirectMatch [<em>status</em> <em>regex
url</em><br>
+ <Strong>Context:</strong> server config, virtual host<br>
+ <strong>Status:</strong> Base<br>
+ <strong>Module:</strong> mod_alias<br>
+ <strong>Compatibility:</strong> Available in Apache 1.3 and later
+ </P>
+
+ <p>This directive is equivilent to <a href="#alias">Redirect</a>, but
+ makes use of standard regular expressions, instead of simple prefix
+ matching. The supplied regular expression is matched against the URL,
+ and if it matches, the server will substitute any parenthesized
+ matches into the given string and use it as a filename. For example,
+ to redirect all GIF files to like-named JPEG files on another server,
+ one might use:
+ <pre>
+ RedirectMatch (.*)\.gif$ http://www.anotherserver.com$1.jpg
+ </pre>
+ </p>
+
+ <hr>
+
<h2><A name="redirecttemp">RedirectTemp directive</A></h2>
<P>
<!--%plaintext <?INDEX {\tt Redirect} directive> -->
***************
*** 181,186 ****
--- 229,256 ----
A request for http://myserver/cgi-bin/foo would cause the server to
run the script /web/cgi-bin/foo.
</P>
+
+ <hr>
+
+ <h2><A name="scriptaliasmatch">ScriptAliasMatch</A></h2>
+ <P>
+ <strong>Syntax:</strong> ScriptAliasMatch <em>regex
directory-filename</em><br>
+ <Strong>Context:</strong> server config, virtual host<br>
+ <strong>Status:</strong> Base<br>
+ <strong>Module:</strong> mod_alias<br>
+ <strong>Compatibility:</strong> Available in Apache 1.3 and later
+ </P>
+
+ <p>This directive is equivilent to <a href="#scriptalias">ScriptAlias</a>,
but
+ makes use of standard regular expressions, instead of simple prefix
+ matching. The supplied regular expression is matched against the URL,
+ and if it matches, the server will substitute any parenthesized
+ matches into the given string and use it as a filename. For example,
+ to activate the standard <code>/cgi-bin</code>, one might use:
+ <pre>
+ ScriptAlias ^/cgi-bin(.*) /usr/local/etc/httpd/cgi-bin$1
+ </pre>
+ </p>
<!--#include virtual="footer.html" -->
</BODY>
1.327 +5 -0 apache/src/CHANGES
Index: CHANGES
===================================================================
RCS file: /export/home/cvs/apache/src/CHANGES,v
retrieving revision 1.326
retrieving revision 1.327
diff -c -C3 -r1.326 -r1.327
*** CHANGES 1997/07/08 02:04:40 1.326
--- CHANGES 1997/07/08 04:45:26 1.327
***************
*** 1,5 ****
--- 1,10 ----
Changes with Apache 1.3
+ *) AliasMatch, ScriptAliasMatch and RedirectMatch directives added,
+ giving regex support to mod_alias. <DirectoryMatch>, <LocationMatch>
+ and <FilesMatch> sections added to succeed <DirectoryMatch ~>, etc...
+ [Alexei Kosut]
+
*) The AccessFileName directive can now take more than one filename.
["Lou D. Langholtz" <[EMAIL PROTECTED]>]
1.92 +20 -3 apache/src/http_core.c
Index: http_core.c
===================================================================
RCS file: /export/home/cvs/apache/src/http_core.c,v
retrieving revision 1.91
retrieving revision 1.92
diff -c -C3 -r1.91 -r1.92
*** http_core.c 1997/07/08 02:04:43 1.91
--- http_core.c 1997/07/08 04:45:27 1.92
***************
*** 637,643 ****
#endif
cmd->override = OR_ALL|ACCESS_CONF;
! if (!strcmp(cmd->path, "~")) {
cmd->path = getword_conf (cmd->pool, &arg);
r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
}
--- 637,646 ----
#endif
cmd->override = OR_ALL|ACCESS_CONF;
! if (cmd->info) { /* <DirectoryMatch> */
! r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
! }
! else if (!strcmp(cmd->path, "~")) {
cmd->path = getword_conf (cmd->pool, &arg);
r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
}
***************
*** 681,687 ****
cmd->path = getword_conf (cmd->pool, &arg);
cmd->override = OR_ALL|ACCESS_CONF;
! if (!strcmp(cmd->path, "~")) {
cmd->path = getword_conf (cmd->pool, &arg);
r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
}
--- 684,693 ----
cmd->path = getword_conf (cmd->pool, &arg);
cmd->override = OR_ALL|ACCESS_CONF;
! if (cmd->info) { /* <LocationMatch> */
! r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
! }
! else if (!strcmp(cmd->path, "~")) {
cmd->path = getword_conf (cmd->pool, &arg);
r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
}
***************
*** 728,734 ****
if (cmd->path)
cmd->override = OR_ALL|ACCESS_CONF;
! if (!strcmp(cmd->path, "~")) {
cmd->path = getword_conf (cmd->pool, &arg);
if (old_path && cmd->path[0] != '/' && cmd->path[0] != '^')
cmd->path = pstrcat(cmd->pool, "^", old_path, cmd->path, NULL);
--- 734,745 ----
if (cmd->path)
cmd->override = OR_ALL|ACCESS_CONF;
! if (cmd->info) { /* <FilesMatch> */
! if (old_path && cmd->path[0] != '/' && cmd->path[0] != '^')
! cmd->path = pstrcat(cmd->pool, "^", old_path, cmd->path, NULL);
! r = pregcomp(cmd->pool, cmd->path, REG_EXTENDED);
! }
! else if (!strcmp(cmd->path, "~")) {
cmd->path = getword_conf (cmd->pool, &arg);
if (old_path && cmd->path[0] != '/' && cmd->path[0] != '^')
cmd->path = pstrcat(cmd->pool, "^", old_path, cmd->path, NULL);
***************
*** 1206,1211 ****
--- 1217,1228 ----
{ "</Limit>", endlimit, NULL, OR_ALL, RAW_ARGS, "Marks end of <Limit>" },
{ "<IfModule", start_ifmod, NULL, OR_ALL, RAW_ARGS, "Container for
directives based on existance of specified modules" },
{ "</IfModule>", end_ifmod, NULL, OR_ALL, NO_ARGS, "Marks end of
<IfModule>" },
+ { "<DirectoryMatch", dirsection, (void*)1, RSRC_CONF, RAW_ARGS, "Container
for directives affecting resources located in the specified directories" },
+ { "</DirectoryMatch>", end_dirsection, NULL, ACCESS_CONF, NO_ARGS, "Marks
end of <DirectoryMatch>" },
+ { "<LocationMatch", urlsection, (void*)1, RSRC_CONF, RAW_ARGS, "Container
for directives affecting resources accessed through the specified URL paths" },
+ { "</LocationMatch>", end_urlsection, NULL, ACCESS_CONF, NO_ARGS, "Marks
end of <LocationMatch>" },
+ { "<FilesMatch", filesection, (void*)1, OR_ALL, RAW_ARGS, "Container for
directives affecting files matching specified patterns" },
+ { "</FilesMatch>", end_filesection, NULL, OR_ALL, NO_ARGS, "Marks end of
<FilesMatch>" },
{ "AuthType", set_string_slot, (void*)XtOffsetOf(core_dir_config,
auth_type),
OR_AUTHCFG, TAKE1, "An HTTP authorization type (e.g., \"Basic\")" },
{ "AuthName", set_string_slot, (void*)XtOffsetOf(core_dir_config,
auth_name),
1.17 +74 -16 apache/src/mod_alias.c
Index: mod_alias.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_alias.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -c -C3 -r1.16 -r1.17
*** mod_alias.c 1997/06/15 19:22:28 1.16
--- mod_alias.c 1997/07/08 04:45:28 1.17
***************
*** 65,70 ****
--- 65,71 ----
char *real;
char *fake;
char *handler;
+ regex_t *regexp;
int redir_status; /* 301, 302, 303, 410, etc */
} alias_entry;
***************
*** 117,123 ****
return a;
}
! const char *add_alias(cmd_parms *cmd, void *dummy, char *f, char *r)
{
server_rec *s = cmd->server;
alias_server_conf *conf =
--- 118,125 ----
return a;
}
! const char *add_alias_internal(cmd_parms *cmd, void *dummy, char *f, char
*r,
! int use_regex)
{
server_rec *s = cmd->server;
alias_server_conf *conf =
***************
*** 126,143 ****
/* XX r can NOT be relative to DocumentRoot here... compat bug. */
new->fake = f; new->real = r; new->handler = cmd->info;
return NULL;
}
! const char *add_redirect(cmd_parms *cmd, alias_dir_conf *dirconf, char
*arg1,
! char *arg2, char *arg3)
{
alias_entry *new;
server_rec *s = cmd->server;
alias_server_conf *serverconf =
(alias_server_conf
*)get_module_config(s->module_config,&alias_module);
int status = (int)cmd->info;
char *f = arg2;
char *url = arg3;
--- 128,162 ----
/* XX r can NOT be relative to DocumentRoot here... compat bug. */
+ if (use_regex) {
+ new->regexp = pregcomp(cmd->pool, f, REG_EXTENDED);
+ if (new->regexp == NULL)
+ return "Regular expression could not be compiled.";
+ }
+
new->fake = f; new->real = r; new->handler = cmd->info;
+
return NULL;
}
! const char *add_alias(cmd_parms *cmd, void *dummy, char *f, char *r) {
! return add_alias_internal(cmd, dummy, f, r, 0);
! }
!
! const char *add_alias_regex(cmd_parms *cmd, void *dummy, char *f, char *r) {
! return add_alias_internal(cmd, dummy, f, r, 1);
! }
!
! const char *add_redirect_internal(cmd_parms *cmd, alias_dir_conf *dirconf,
! char *arg1, char *arg2, char *arg3,
! int use_regex)
{
alias_entry *new;
server_rec *s = cmd->server;
alias_server_conf *serverconf =
(alias_server_conf
*)get_module_config(s->module_config,&alias_module);
int status = (int)cmd->info;
+ regex_t *r = NULL;
char *f = arg2;
char *url = arg3;
***************
*** 156,161 ****
--- 175,186 ----
url = arg2;
}
+ if (use_regex) {
+ r = pregcomp(cmd->pool, f, REG_EXTENDED);
+ if (r == NULL)
+ return "Regular expression could not be compiled.";
+ }
+
if (is_HTTP_REDIRECT(status)) {
if (!url) return "URL to redirect to is missing";
if (!is_url (url)) return "Redirect to non-URL";
***************
*** 169,179 ****
else
new = push_array (serverconf->redirects);
! new->fake = f; new->real = url;
new->redir_status = status;
return NULL;
}
command_rec alias_cmds[] = {
{ "Alias", add_alias, NULL, RSRC_CONF, TAKE2,
"a fakename and a realname"},
--- 194,214 ----
else
new = push_array (serverconf->redirects);
! new->fake = f; new->real = url; new->regexp = r;
new->redir_status = status;
return NULL;
}
+ const char *add_redirect(cmd_parms *cmd, alias_dir_conf *dirconf, char
*arg1,
+ char *arg2, char *arg3) {
+ return add_redirect_internal(cmd, dirconf, arg1, arg2, arg3, 0);
+ }
+
+ const char *add_redirect_regex(cmd_parms *cmd, alias_dir_conf *dirconf,
+ char *arg1, char *arg2, char *arg3) {
+ return add_redirect_internal(cmd, dirconf, arg1, arg2, arg3, 1);
+ }
+
command_rec alias_cmds[] = {
{ "Alias", add_alias, NULL, RSRC_CONF, TAKE2,
"a fakename and a realname"},
***************
*** 182,187 ****
--- 217,229 ----
{ "Redirect", add_redirect, (void*)HTTP_MOVED_TEMPORARILY,
OR_FILEINFO, TAKE23,
"an optional status, then document to be redirected and destination
URL" },
+ { "AliasMatch", add_alias_regex, NULL, RSRC_CONF, TAKE2,
+ "a regular expression and a filename"},
+ { "ScriptAliasMatch", add_alias_regex, "cgi-script", RSRC_CONF, TAKE2,
+ "a regular expression and a filename"},
+ { "RedirectMatch", add_redirect_regex, (void*)HTTP_MOVED_TEMPORARILY,
+ OR_FILEINFO, TAKE23,
+ "an optional status, then a regular expression and destination URL" },
{ "RedirectTemp", add_redirect, (void*)HTTP_MOVED_TEMPORARILY,
OR_FILEINFO, TAKE2,
"a document to be redirected, then the destination URL" },
***************
*** 228,255 ****
char *try_alias_list (request_rec *r, array_header *aliases, int doesc, int
*status)
{
alias_entry *entries = (alias_entry *)aliases->elts;
int i;
for (i = 0; i < aliases->nelts; ++i) {
alias_entry *p = &entries[i];
! int l = alias_matches (r->uri, p->fake);
! if (l > 0) {
if (p->handler) { /* Set handler, and leave a note for mod_cgi */
! r->handler = pstrdup(r->pool, p->handler);
table_set (r->notes, "alias-forced-type", p->handler);
}
!
*status = p->redir_status;
! if (doesc) {
! char *escurl;
! escurl = os_escape_path(r->pool, r->uri + l, 1);
!
! return pstrcat(r->pool, p->real, escurl, NULL);
! } else
! return pstrcat(r->pool, p->real, r->uri + l, NULL);
! }
}
return NULL;
--- 270,313 ----
char *try_alias_list (request_rec *r, array_header *aliases, int doesc, int
*status)
{
alias_entry *entries = (alias_entry *)aliases->elts;
+ regmatch_t regm[10];
+ char *found = NULL;
int i;
for (i = 0; i < aliases->nelts; ++i) {
alias_entry *p = &entries[i];
! int l;
!
! if (p->regexp) {
! if (!regexec(p->regexp, r->uri, p->regexp->re_nsub+1, regm, 0))
! found = pregsub(r->pool, p->real, r->uri,
! p->regexp->re_nsub+1, regm);
! }
! else {
! l = alias_matches (r->uri, p->fake);
! if (l > 0) {
! if (doesc) {
! char *escurl;
! escurl = os_escape_path(r->pool, r->uri + l, 1);
!
! found = pstrcat(r->pool, p->real, escurl, NULL);
! } else
! found = pstrcat(r->pool, p->real, r->uri + l, NULL);
! }
! }
!
! if (found) {
if (p->handler) { /* Set handler, and leave a note for mod_cgi */
! r->handler = pstrdup(r->pool, p->handler);
table_set (r->notes, "alias-forced-type", p->handler);
}
!
*status = p->redir_status;
! return found;
! }
!
}
return NULL;