From 8bc29250967e37b99fa55569bec45685be1cc26e Mon Sep 17 00:00:00 2001 From: David Cook Date: Tue, 3 Jul 2018 19:04:50 +1000 Subject: [PATCH] Bug 21031 - Apache Rewrite rules don't work for API when using anything but Debian package Plack configuration The Rewrite rules for Apache don't work unless you're using debian/templates/apache-shared-opac-plack.conf or debian/templates/apache-shared-intranet-plack.conf. This patch fixes the Rewrite rules for the non-Plack Debian Apache configuration templates as well as the standard Apache configuration file that comes with Koha. __BEFORE APPLYING__ 1. Visit /api/v1/app.pl/api/v1/spec on your git dev install 2. This should display a large page of JSON 3. Visit /api/v1/spec on your git dev install 4. This should generate a 404 error __APPLY PATCH__ __AFTER APPLYING__ 5. Visit /api/v1/app.pl/api/v1/spec on your git dev install 6. This should display a large page of JSON 7. Visit /api/v1/spec on your git dev install 8. This should display a large page of JSON (identical to the one from earlier steps) --- debian/templates/apache-shared-intranet.conf | 6 ++---- debian/templates/apache-shared-opac.conf | 6 ++---- etc/koha-httpd.conf | 13 +++++-------- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/debian/templates/apache-shared-intranet.conf b/debian/templates/apache-shared-intranet.conf index e1aef5e9d4..1d347059a0 100644 --- a/debian/templates/apache-shared-intranet.conf +++ b/debian/templates/apache-shared-intranet.conf @@ -27,8 +27,6 @@ Alias "/api" "/usr/share/koha/api" SetEnv MOJO_MODE "production" RewriteBase /api/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{DOCUMENT_ROOT}/../api/$1/app.pl -f - RewriteRule ^(.*?)/.* $1/app.pl/api/$0 [L] + RewriteCond %{REQUEST_URI} !^/api/v[0-1]+/app.pl + RewriteRule ^(v[0-9]+)/(.*)$ /api/$1/app.pl/api/$1/$2 [L] diff --git a/debian/templates/apache-shared-opac.conf b/debian/templates/apache-shared-opac.conf index 7adcb4aa0b..2a7e9ace16 100644 --- a/debian/templates/apache-shared-opac.conf +++ b/debian/templates/apache-shared-opac.conf @@ -34,8 +34,6 @@ Alias "/api" "/usr/share/koha/api" SetEnv MOJO_MODE "production" RewriteBase /api/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{DOCUMENT_ROOT}/../api/$1/app.pl -f - RewriteRule ^(.*?)/.* $1/app.pl/api/$0 [L] + RewriteCond %{REQUEST_URI} !^/api/v[0-1]+/app.pl + RewriteRule ^(v[0-9]+)/(.*)$ /api/$1/app.pl/api/$1/$2 [L] diff --git a/etc/koha-httpd.conf b/etc/koha-httpd.conf index 6f51ace860..d0f619efdb 100644 --- a/etc/koha-httpd.conf +++ b/etc/koha-httpd.conf @@ -123,10 +123,9 @@ RewriteEngine On RewriteBase /api/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{DOCUMENT_ROOT}/../api/$1/app.pl -f - RewriteRule ^(.*?)/.* $1/app.pl/api/$0 [L] + RewriteCond %{REQUEST_URI} !^/api/v[0-1]+/app.pl + RewriteRule ^(v[0-9]+)/(.*)$ /api/$1/app.pl/api/$1/$2 [L] + @@ -250,10 +249,8 @@ RewriteEngine On RewriteBase /api/ - RewriteCond %{REQUEST_FILENAME} !-f - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{DOCUMENT_ROOT}/../api/$1/app.pl -f - RewriteRule ^(.*?)/.* $1/app.pl/api/$0 [L] + RewriteCond %{REQUEST_URI} !^/api/v[0-1]+/app.pl + RewriteRule ^(v[0-9]+)/(.*)$ /api/$1/app.pl/api/$1/$2 [L] -- 2.13.6