Hi! A customer wants to access branches/branchgroups via a subpath, instead of the more common / documented way of setting up a subdomain per branch: https://wiki.koha-community.org/wiki/Override_sysprefs_in_Apache_config
So instead of https://aaa.library.example.com/ they want https://library.example.com/aaa/ (for ~10 branches) This boils down to: - matching the path and munging the URL - setting some ENV vars (OPAC_SEARCH_LIMIT, OPAC_CSS_OVERRIDE, etc) - munging the HTML generated by Koha to fix the links While this could be implemented via carefull application of various Apache modules (mod_proxy, mod_rewrite, mod_proxy_html) I feel more comfortable implementing this in Perl in a Plack Middleware. The result is not very pretty, but seems to work (see attached code...) But to load the middleware, I have to enable it in /etc/koha/plack.psgi and thus change a core file (or copy upstream plack.psgi and edit the copy, which still means that we'll have to apply our changes after each update) In theory we could add some config to load custom Middlewares, but as the load order of Middlewares is very relevant, this seems hardly doable - unless we start with one middleware config slot at the location I need :-) Anyway, I think we'll just go with maintaining a custom plack.psgi, unless anybody here has any other ideas / best practices / solutions on how to mount library branches at location/sub-dirs... I'm also not sure if this feature is on any roadmap etc. Greetings, domm -- #!/usr/bin/perl https://domm.plix.at for(ref bless{},just'another'perl'hacker){s-:+-$"-g&&print$_.$/}
package Libelle::Middleware::IsolateBranch; use strict; use warnings; use parent 'Plack::Middleware'; use Plack::Request; use Plack::Response; my %BRANCHES = ( aaa => { css => 'aaa.css', search => 'branch:ICF', }, ccc => { css => 'bbb.css', search => 'branch:BBB', }, xxx => { css => 'ccc.css', search => 'branch:CCC', }, ); # could be passed when init middleware my $regex = '^/('.join('|',keys %BRANCHES).')/'; sub call { my $self = shift; my $env = shift; my $path = $env->{PATH_INFO}; if ($path =~m{$regex}) { my $branch = $1; $path=~s{^/$branch/}{/}; $env->{PATH_INFO} = $path; $env->{OPAC_CSS_OVERRIDE} = $BRANCHES{$branch}->{css}; $env->{OPAC_SEARCH_LIMIT} = $BRANCHES{$branch}->{search}; $env->{OPAC_LIMIT_OVERRIDE} = '1'; # call Koha my $res = Plack::Response->new(@{$self->app->($env)}); # fix links in response, ugly and maybe not stable if ($res->content_type =~m{^text/html}) { my $raw_body = $res->body; my $body = ref($raw_body) eq 'ARRAY' ? join('',@$raw_body) : $raw_body; $body=~s{/cgi-bin}{/$branch/cgi-bin}g; $res->body($body); } elsif ($res->status == 302) { my $target = $res->location; $target=~s{/cgi-bin}{/$branch/cgi-bin}g; $res->redirect($target); } return $res->finalize; } else { return $self->app->($env); } } 1; =pod Needs to be enabled in /etc/koha/plack.psgi use Libelle::Middleware::IsolateBranch; ... builder { ... enable 'Libelle::Middleware::IsolateBranch'; # between Static and SetEnv ... } And needs some Apache Config adaptions: /etc/koha/apache-shared-opac-plack.conf RewriteRule "^/(aaa|bbb|ccc)$" "/$1/" [L,PT] ProxyPassMatch "^/(aaa|bbb|ccc)/" "http://koha:5005/$1/opac/opac-main.pl" ProxyPassMatch "^/(aaa|bbb|ccc)/cgi-bin/koha" "http://koha:5005/$1/opac" ProxyPassReverse /aaa/ "http://koha:5005/aaa/opac/opac-main.pl" ProxyPassReverse /aaa/cgi-bin/koha "http://koha:5005/aaa/opac" ProxyPassReverse /bbb/ "http://koha:5005/bbb/opac/opac-main.pl" ProxyPassReverse /bbb/cgi-bin/koha "http://koha:5005/bbb/opac" ProxyPassReverse /ccc/ "http://koha:5005/ccc/opac/opac-main.pl" ProxyPassReverse /ccc/cgi-bin/koha "http://koha:5005/ccc/opac"
_______________________________________________ Koha-devel mailing list Koha-devel@lists.koha-community.org https://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel website : https://www.koha-community.org/ git : https://git.koha-community.org/ bugs : https://bugs.koha-community.org/