web staff : dynamic apache index delivery
authorBill Erickson <berick@esilibrary.com>
Thu, 12 Dec 2013 14:17:06 +0000 (09:17 -0500)
committerBill Erickson <berick@esilibrary.com>
Thu, 12 Dec 2013 14:17:06 +0000 (09:17 -0500)
Generic apache config wasn't working, since different apps create
arbitrarily nested URL parameters, which means each app would need its
own Apache rewrite configuration to sort them all out.

This creates a new OILSWebStopAtIndex EGWeb.pm option which tells the
code to check for the presence of an index file at the current directory
as it's looking up the directory tree for the requested template.

Example w/ stop-at-index enabled.

The code will look for these templates in this order:

URL -> /eg/staff/circ/patron/142/holds

1. staff/circ/patron/142/holds.tt2
2. staff/circ/patron/142/index.tt2
3. staff/circ/patron/142.tt2
4. staff/circ/patron/index.tt2 -- file exists, all done.

Signed-off-by: Bill Erickson <berick@esilibrary.com>
Open-ILS/examples/apache/eg_vhost.conf.in
Open-ILS/examples/apache_24/eg_vhost.conf.in
Open-ILS/src/perlmods/lib/OpenILS/WWW/EGWeb.pm

index 32ebd26..5305d0b 100644 (file)
@@ -789,17 +789,13 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT]
 
 <LocationMatch /eg/staff/>
     Options -MultiViews
+    PerlSetVar OILSWebStopAtIndex "true"
 
     # map /eg/staff to /eg/staff/index
     RewriteEngine On
     RewriteCond %{PATH_INFO} =/staff/
     RewriteRule (.*) /eg/staff/index [L,DPI]
 
-    # map /eg/staff/foo/bar to /eg/staff/foo/index
-    RewriteEngine On
-    RewriteCond %{PATH_INFO} !.*/(index|css|t_*)
-    RewriteRule (.*)/[^\/]+$ $1/index [L,DPI]
-
     <IfModule mod_headers.c>
         Header append Cache-Control "public"
     </IFModule>
index 1f90e84..dfdeb55 100644 (file)
@@ -801,17 +801,13 @@ RewriteRule ^/openurl$ ${openurl:%1} [NE,PT]
 
 <LocationMatch /eg/staff/>
     Options -MultiViews
+    PerlSetVar OILSWebStopAtIndex "true"
 
     # map /eg/staff to /eg/staff/index
     RewriteEngine On
     RewriteCond %{PATH_INFO} =/staff/
     RewriteRule (.*) /eg/staff/index [L,DPI]
 
-    # map /eg/staff/foo/bar to /eg/staff/foo/index
-    RewriteEngine On
-    RewriteCond %{PATH_INFO} !.*/(index|css|t_*)
-    RewriteRule (.*)/[^\/]+$ $1/index [L,DPI]
-
     <IfModule mod_headers.c>
         Header append Cache-Control "public"
     </IFModule>
index 2e557db..4d00a3f 100644 (file)
@@ -235,6 +235,7 @@ sub find_template {
     my $page_args = [];
     my $as_xml = $r->dir_config('OILSWebForceValidXML');
     my $ext = $r->dir_config('OILSWebDefaultTemplateExtension');
+    my $at_index = $r->dir_config('OILSWebStopAtIndex');
 
     my @parts = split('/', $path);
     my $localpath = $path;
@@ -253,9 +254,27 @@ sub find_template {
             if(-r $fpath) {
                 $template = "$localpath.$ext";
                 last;
+            } 
+        }
+        last if $template;
+
+        if ($at_index) {
+            # no matching template was found in the current directory.
+            # stop-at-index requested; see if there is an index.ext 
+            # file in the same directory instead.
+            for my $tpath (@{$ctx->{template_paths}}) {
+                # replace the final path component with 'index'
+                $localpath =~ s|/[^/]+$|/index|;
+                my $fpath = "$tpath/$localpath.$ext";
+                $r->log->debug("egweb: looking at possible template $fpath");
+                if (-r $fpath) {
+                    $template = "$localpath.$ext";
+                    last;
+                }
             }
         }
         last if $template;
+
         push(@args, pop @parts);
         $localpath = join('/', @parts);
     }