brian 96/11/18 12:47:22
Modified: src mod_alias.c
Log:
Reviewed by: Mark Cox, Brian Behlendorf
Submitted by: Paul Sutton
Fixed errors with RedirectTemp and RedirectPermanent directives, as well as
added the ability to redirect using any 3xx class of error.
Revision Changes Path
1.11 +37 -13 apache/src/mod_alias.c
Index: mod_alias.c
===================================================================
RCS file: /export/home/cvs/apache/src/mod_alias.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -C3 -r1.10 -r1.11
*** mod_alias.c 1996/11/04 09:34:04 1.10
--- mod_alias.c 1996/11/18 20:47:19 1.11
***************
*** 65,71 ****
char *real;
char *fake;
char *handler;
! int redir_status; /* 301, 302, 303 */
} alias_entry;
typedef struct {
--- 65,71 ----
char *real;
char *fake;
char *handler;
! int redir_status; /* 301, 302, 303, 410, etc */
} alias_entry;
typedef struct {
***************
*** 130,150 ****
return NULL;
}
! const char *add_redirect(cmd_parms *cmd, alias_dir_conf *dirconf, char *f,
! char *url)
{
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;
! if (!strcasecmp(url, "gone"))
status = HTTP_GONE;
else {
if (!is_url (url)) return "Redirect to non-URL";
- status = (int)cmd->info;
}
if ( cmd->path )
new = push_array (dirconf->redirects);
else
--- 130,169 ----
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;
! if (!strcasecmp(arg1, "gone"))
status = HTTP_GONE;
+ else if (!strcasecmp(arg1, "permanent"))
+ status = HTTP_MOVED_PERMANENTLY;
+ else if (!strcasecmp(arg1, "temp"))
+ status = HTTP_MOVED_TEMPORARILY;
+ else if (!strcasecmp(arg1, "seeother"))
+ status = HTTP_SEE_OTHER;
+ else if (isdigit(*arg1))
+ status = atoi(arg1);
else {
+ f = arg1;
+ url = arg2;
+ }
+
+ if (is_HTTP_REDIRECT(status)) {
+ if (!url) return "URL to redirect to is missing";
if (!is_url (url)) return "Redirect to non-URL";
}
+ else {
+ if (url) return "Redirect URL not valid for this status";
+ }
+
if ( cmd->path )
new = push_array (dirconf->redirects);
else
***************
*** 160,171 ****
"a fakename and a realname"},
{ "ScriptAlias", add_alias, "cgi-script", RSRC_CONF, TAKE2,
"a fakename and a realname"},
! { "Redirect", add_redirect, (void*)302, OR_FILEINFO, TAKE2,
! "a document to be redirected, then the destination URL (or \"Gone\")" },
! { "RedirectTemp", add_redirect, (void*)302, OR_FILEINFO, TAKE2,
! "a document to be redirected, then the destination URL" },
! { "RedirectPermanent", add_redirect, (void*)301, OR_FILEINFO, TAKE2,
"a document to be redirected, then the destination URL" },
{ NULL }
};
--- 179,193 ----
"a fakename and a realname"},
{ "ScriptAlias", add_alias, "cgi-script", RSRC_CONF, TAKE2,
"a fakename and a realname"},
! { "Redirect", add_redirect, (void*)HTTP_MOVED_TEMPORARILY,
! OR_FILEINFO, TAKE23,
! "an optional status, then document to be redirected and destination
URL" },
! { "RedirectTemp", add_redirect, (void*)HTTP_MOVED_TEMPORARILY,
! OR_FILEINFO, TAKE2,
"a document to be redirected, then the destination URL" },
+ { "RedirectPermanent", add_redirect, (void*)HTTP_MOVED_PERMANENTLY,
+ OR_FILEINFO, TAKE2,
+ "a document to be redirected, then the destination URL" },
{ NULL }
};
***************
*** 250,256 ****
return DECLINED;
if ((ret = try_alias_list (r, serverconf->redirects, 1, &status)) !=
NULL) {
! table_set (r->headers_out, "Location", ret);
return status;
}
--- 272,279 ----
return DECLINED;
if ((ret = try_alias_list (r, serverconf->redirects, 1, &status)) !=
NULL) {
! if (is_HTTP_REDIRECT(status))
! table_set (r->headers_out, "Location", ret);
return status;
}
***************
*** 273,279 ****
/* It may have changed since last time, so try again */
if ((ret = try_alias_list (r, dirconf->redirects, 1, &status)) != NULL)
{
! table_set (r->headers_out, "Location", ret);
return status;
}
--- 296,303 ----
/* It may have changed since last time, so try again */
if ((ret = try_alias_list (r, dirconf->redirects, 1, &status)) != NULL)
{
! if (is_HTTP_REDIRECT(status))
! table_set (r->headers_out, "Location", ret);
return status;
}