You are viewing a plain text version of this content. The canonical link for it is here.
Posted to axkit-dev@xml.apache.org by ma...@sergeant.org on 2006/08/07 02:32:10 UTC

[SVN] [53] Redirect a dir request without / to the right dir.

Revision: 53
Author:   matt
Date:     2006-08-07 00:31:45 +0000 (Mon, 07 Aug 2006)

Log Message:
-----------
Redirect a dir request without / to the right dir.

Modified Paths:
--------------
    trunk/plugins/uri_to_file

Modified: trunk/plugins/uri_to_file
===================================================================
--- trunk/plugins/uri_to_file	2006-08-07 00:20:15 UTC (rev 52)
+++ trunk/plugins/uri_to_file	2006-08-07 00:31:45 UTC (rev 53)
@@ -8,8 +8,12 @@
     
     $self->log(LOGINFO, "translate: $uri");
     
-    $uri =~ s/\?.*//;
     
+    $uri =~ s/(\?.*)//;
+    my $removed = $1 || '';
+    
+    my $original_uri = $uri;
+    
     $uri = uri_decode($uri);
     
     my $root = $self->config->path;
@@ -18,6 +22,24 @@
     
     my $path = canonpath(catfile($self->config->docroot, $uri));
     if (-d $path) {
+        if ($uri !~ /\/$/) {
+            # send redirect?
+            $self->client->headers_out->code(302, "Found");
+            $self->client->headers_out->header('Location', "$original_uri/$removed");
+            $self->client->headers_out->header('Content-Type', 'text/html');
+            $self->client->send_http_headers;
+            $self->client->write(<<EOT);
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
+<HTML><HEAD>
+<TITLE>302 Found</TITLE>
+</HEAD><BODY>
+<H1>Found</H1>
+The document has moved <A HREF="$original_uri/$removed">here</A>.<P>
+<HR>
+</BODY></HTML>
+EOT
+            return DONE;
+        }
         my $filepath = catfile($path, $self->config->dirindex);
         $path = $filepath if -f $filepath;
     }