You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Paul Sutton <pa...@ukweb.com> on 1996/10/08 09:50:07 UTC

add perm redirect, NCSA compatible

The patch below adds NCSA-style RedirectPermanent and RedirectTemp
directives, to return 302 and 301 statuses. It could easily be extended to
handle a directive to return 303 (See Other), or even - with a special
case check to not return Location - 410 (Gone) status. Incidently, the
text associated with 302 is still "Found", which should probably be
changed to "Redirect Temporarily" to match HTTP/1.1.

Incidently I added the new directives because they are NCSA-compatible.
However I would prefer to use an optional argument to Redirect
to give the status - this also makes it extensible if any other return
statuses are added in the future, eg

  Redirect /path http://some.com/
  Redirect Temporary /path http://some.com/
  Redirect Permanent /path http://some.com/
  Redirect SeeOther /path http://some.com/
  Redirect 301 /path http://some.com/

This would require my TAKE23 patch...

Paul
UK Web Ltd

*** mod_alias.c.dist	Tue Oct  8 08:30:47 1996
--- mod_alias.c	Tue Oct  8 08:33:46 1996
***************
*** 67,72 ****
--- 67,73 ----
      char *real;
      char *fake;
      char *handler;
+     int status;
  } alias_entry;

  typedef struct {
***************
*** 147,152 ****
--- 148,154 ----
          new = push_array (serverconf->redirects);
      }
      new->fake = f; new->real = url;
+     new->status = (int)cmd->info;
      return NULL;
  }

***************
*** 155,161 ****
      "a fakename and a realname"},
  { "ScriptAlias", add_alias, "cgi-script", RSRC_CONF, TAKE2,
      "a fakename and a realname"},
! { "Redirect", add_redirect, NULL, OR_FILEINFO, TAKE2,
      "a document to be redirected, then the destination URL" },
  { NULL }
  };
--- 157,167 ----
      "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" },
! { "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 }
  };
***************
*** 194,200 ****
      return urip - uri;
  }

! char *try_alias_list (request_rec *r, array_header *aliases, int doesc)
  {
      alias_entry *entries = (alias_entry *)aliases->elts;
      int i;
--- 200,206 ----
      return urip - uri;
  }

! char *try_alias_list (request_rec *r, array_header *aliases, int doesc, int *status)
  {
      alias_entry *entries = (alias_entry *)aliases->elts;
      int i;
***************
*** 209,214 ****
--- 215,222 ----
  		table_set (r->notes, "alias-forced-type", p->handler);
  	    }

+ 	    *status = p->status;
+
  	    if (doesc) {
  		char *escurl;
  		escurl = os_escape_path(r->pool, r->uri + l, 1);
***************
*** 227,232 ****
--- 235,241 ----
      alias_server_conf *serverconf =
          (alias_server_conf *)get_module_config(sconf, &alias_module);
      char *ret;
+     int status;

  #ifdef __EMX__
      /* Add support for OS/2 drive names */
***************
*** 236,247 ****
  #endif
          return DECLINED;

!     if ((ret = try_alias_list (r, serverconf->redirects, 1)) != NULL) {
          table_set (r->headers_out, "Location", ret);
!         return REDIRECT;
      }

!     if ((ret = try_alias_list (r, serverconf->aliases, 0)) != NULL) {
          r->filename = ret;
          return OK;
      }
--- 245,256 ----
  #endif
          return DECLINED;

!     if ((ret = try_alias_list (r, serverconf->redirects, 1, &status)) !=NULL) {
          table_set (r->headers_out, "Location", ret);
!         return status;
      }

!     if ((ret = try_alias_list (r, serverconf->aliases, 0, &status)) != NULL) {
          r->filename = ret;
          return OK;
      }
***************
*** 255,266 ****
      alias_dir_conf *dirconf =
          (alias_dir_conf *)get_module_config(dconf, &alias_module);
      char *ret;

      /* It may have changed since last time, so try again */

!     if ((ret = try_alias_list (r, dirconf->redirects, 1)) != NULL) {
          table_set (r->headers_out, "Location", ret);
!         return REDIRECT;
      }

      return DECLINED;
--- 264,276 ----
      alias_dir_conf *dirconf =
          (alias_dir_conf *)get_module_config(dconf, &alias_module);
      char *ret;
+     int status;

      /* 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;
      }

      return DECLINED;


Re: add perm redirect, NCSA compatible

Posted by Brandon Long <bl...@uiuc.edu>.
On 10/8, Paul Sutton uttered the following other thing:
> The patch below adds NCSA-style RedirectPermanent and RedirectTemp
> directives, to return 302 and 301 statuses. It could easily be extended to
> handle a directive to return 303 (See Other), or even - with a special
> case check to not return Location - 410 (Gone) status. Incidently, the
> text associated with 302 is still "Found", which should probably be
> changed to "Redirect Temporarily" to match HTTP/1.1.
> 
> Incidently I added the new directives because they are NCSA-compatible.
> However I would prefer to use an optional argument to Redirect
> to give the status - this also makes it extensible if any other return
> statuses are added in the future, eg
> 
>   Redirect /path http://some.com/
>   Redirect Temporary /path http://some.com/
>   Redirect Permanent /path http://some.com/
>   Redirect SeeOther /path http://some.com/
>   Redirect 301 /path http://some.com/

It might be worth just allowing the user to specify status code for
a particular document (assuming that apache would then provide an 
appropriate document or error message for the return type).

Return 410 /path

Or, I guess it could be in a <Location> or <Directory> directive.

Brandon

-- 
 Brandon Long         "Investment in reliability increases until it
 MD6 Crash Test Dummy   exceeds the probable cost of errors, or until
 Intel Corp, Oregon      someone insists on getting some useful work done."
          I'm too low on the totem pole to speak for Intel.
                  http://www.uiuc.edu/ph/www/blong