Bug 41167

Summary: Rewrite Rules missing in etc/koha-httpd.conf
Product: Koha Reporter: vivek <vivek.openlx>
Component: Installation and upgrade (command-line installer)Assignee: vivek <vivek.openlx>
Status: Pushed to oldstable --- QA Contact: Marcel de Rooy <m.de.rooy>
Severity: major    
Priority: P5 - low CC: dcook, fridolin.somers, jonathan.druart, m.de.rooy, paul.derscheid, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38010
GIT URL: Initiative type: ---
Sponsorship status: --- Comma delimited list of Sponsors:
Crowdfunding goal: 0 Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
25.11.00,25.05.06,24.11.11
Circulation function:
Bug Depends on:    
Bug Blocks: 37893    
Attachments: Proposed patch for Bug 41167 – Add missing rewrite rules in koha-httpd.conf
Follow-up patch for Bug 41167 – Correct rewrite rules in koha-httpd.conf
Bug 41167: Fix missing rewrite rules in koha-httpd.conf
Bug 41167: (follow-up) Correct rewrite rules in koha-httpd.conf
Bug 41167: Fix missing rewrite rules in koha-httpd.conf
Bug 41167: Add test to compare both apache conf
Bug 41167: Fix missing rewrite rules in koha-httpd.conf
Bug 41167: Add test to compare both apache conf
Bug 41167: Add missing line to etx/koha-httpd.conf

Description vivek 2025-11-03 04:50:34 UTC
Dear Koha Team,

In the Koha 25.05.x version, I noticed that the file koha-httpd.conf in the tarball (or Git-based) installation is missing several important rewrite rules under the intranet section.

Because of this, when Koha is installed from source (tar or Git), many modules on the staff interface (such as Acquisitions) do not function correctly.

However, when Koha is installed via APT packages, the correct koha-httpd.conf file is included, and everything works properly.

The following rewrite rules are missing and should be added:

RewriteRule ^/cgi-bin/koha/erm/.$ /cgi-bin/koha/erm/erm.pl [PT]
RewriteCond %{REQUEST_URI} !^/cgi-bin/koha/preservation/..pl$
RewriteRule ^/cgi-bin/koha/preservation/.$ /cgi-bin/koha/preservation/home.pl [PT]
RewriteRule ^/cgi-bin/koha/admin/record_sources(.)?$ /cgi-bin/koha/admin/record_sources.pl$1 [PT]
RewriteCond %{QUERY_STRING} booksellerid=(.)
RewriteRule ^/cgi-bin/koha/acqui/supplier.pl$ /cgi-bin/koha/acquisition/vendors/%1? [R]
RewriteRule ^/cgi-bin/koha/acquisition/vendors(.)?$ /cgi-bin/koha/acqui/vendors.pl$1 [PT]

Please include these rules in the official koha-httpd.conf source TAR package file for future releases to ensure full functionality when Koha is installed from the tarball or Git source.

Thank you for your attention to this issue.
Comment 1 David Cook 2025-11-03 05:03:33 UTC
Looking at "etc/koha-httpd.conf", it looks like the erm and preservation rules have been put into the OPAC virtualhost by accident instead of the staff interface virtualhost.

And it does look like the others are missing all together. 

This should've been caught during QA of those changes.
Comment 2 vivek 2025-11-03 06:30:31 UTC
Created attachment 188883 [details] [review]
Proposed patch for Bug 41167 – Add missing rewrite rules in koha-httpd.conf

Proposed patch for Bug 41167.

This patch adds missing RewriteRules for ERM, Preservation and Acquisition modules in koha-httpd.conf to restore staff client functionality.

Test plan:
1. Apply patch
2. Restart Apache
3. Access acquisitions and ERM pages
4. Confirm functionality restored

Signed-off-by: Vivek Kumar <vivek.kumar@bestbookbuddies.com>"
Comment 3 David Cook 2025-11-06 04:16:20 UTC
Thanks for the patch, Vivek, but it looks like there's quite a few mistakes. For instance, you're missing asterisks throughout the rules. 

You'll also need to remove the two erroneous RewriteRules from the OPAC virtualhost:

RewriteRule ^/cgi-bin/koha/erm/.*$ /cgi-bin/koha/erm/erm.pl [PT]
RewriteRule ^/cgi-bin/koha/preservation/.*$ /cgi-bin/koha/preservation/home.pl [PT]
Comment 4 David Cook 2025-11-06 04:17:22 UTC Comment hidden (obsolete)
Comment 5 David Cook 2025-11-06 04:17:49 UTC
For reviewers, the following rules come from debian/templates/apache-shared-intranet.conf:

RewriteRule ^/cgi-bin/koha/erm/.*$ /cgi-bin/koha/erm/erm.pl [PT]
RewriteCond %{REQUEST_URI} !^/cgi-bin/koha/preservation/.*.pl$
RewriteRule ^/cgi-bin/koha/preservation/.*$ /cgi-bin/koha/preservation/home.pl [PT]
RewriteRule ^/cgi-bin/koha/admin/record_sources(.*)?$ /cgi-bin/koha/admin/record_sources.pl$1 [PT]
RewriteCond %{QUERY_STRING} booksellerid=(.*)
RewriteRule ^/cgi-bin/koha/acqui/supplier.pl$ /cgi-bin/koha/acquisition/vendors/%1? [R]
RewriteRule ^/cgi-bin/koha/acquisition/vendors(.*)?$ /cgi-bin/koha/acqui/vendors.pl$1 [PT]
Comment 6 David Cook 2025-11-06 04:23:13 UTC
(In reply to vivek from comment #2)
> Test plan:
> 1. Apply patch
> 2. Restart Apache
> 3. Access acquisitions and ERM pages
> 4. Confirm functionality restored

This test plan won't work for anyone using koha-testing-docker, which means it'll be tricky to get someone to test. I'm still thinking about how I'd test this in koha-testing-docker. 

Because of the nature of the patch, we might be able to get away with just a visual review, but I'm not sure.

When you provide an updated patch, I might tweak my KTD to expose a couple extra ports, and then do a "single" installation which will work with it.
Comment 7 vivek 2025-11-06 05:23:33 UTC
Created attachment 189141 [details] [review]
Follow-up patch for Bug 41167 – Correct rewrite rules in koha-httpd.conf

This is a follow-up patch for Bug 41167 – Add missing rewrite rules in koha-httpd.conf.

Changes made in this follow-up:
- Added missing asterisks (*) in rewrite rule patterns.
- Removed two erroneous RewriteRules from the OPAC virtualhost.
- Ensured all ERM, Preservation, and Acquisition rewrite rules are correctly placed under the intranet virtualhost.

These corrections address the issues noted by David Cook in Comment 3 and Comment 5.

Test plan:
1. Apply patch.
2. Restart Apache.
3. Access ERM, Preservation, and Acquisitions modules in the staff interface.
4. Confirm all pages load correctly without 404 errors or misrouted URLs.
Comment 8 David Cook 2025-11-07 05:01:13 UTC
Created attachment 189248 [details] [review]
Bug 41167: Fix missing rewrite rules in koha-httpd.conf

This patch adds missing RewriteRules for ERM, Preservation and Acquisition modules in koha-httpd.conf to restore staff client functionality.

Test plan:
1. Apply patch
2. Restart Apache
3. Access acquisitions and ERM pages
4. Confirm functionality restored

Signed-off-by: Vivek Kumar <vivek.kumar@bestbookbuddies.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Comment 9 David Cook 2025-11-07 05:01:16 UTC
Created attachment 189249 [details] [review]
Bug 41167: (follow-up) Correct rewrite rules in koha-httpd.conf

This follow-up patch fixes issues from the initial patch for Bug 41167:
- Adds missing asterisks (*) in rewrite rule patterns
- Removes erroneous RewriteRules from the OPAC virtualhost
- Ensures all ERM, Preservation, and Acquisition rewrite rules are correctly placed under the intranet virtualhost

Test plan:
1. Apply patch
2. Restart Apache
3. Access ERM, Preservation, and Acquisitions modules
4. Confirm pages load correctly without 404 or routing errors

Signed-off-by: Vivek Kumar <vivek.kumar@bestbookbuddies.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>
Comment 10 David Cook 2025-11-07 05:02:17 UTC
Fixed up the commit title on the second patch. These probably could've been squashed into two patches, but I left them as two separate ones anyway. 

Overall, it looks good. I'll include my test plan in a separate comment.
Comment 11 David Cook 2025-11-07 05:02:23 UTC
Test plan:
0. sudo mkdir /opt/koha
1. sudo chown -R kohadev-koha:kohadev-koha /opt/koha
2a. perl Makefile.PL
2b. Installation mode (dev, single, standard) [standard] single
2c. Please specify the directory in which to install Koha [/var/lib/koha/kohadev/koha] /opt/koha
2d. Use defaults for the rest
3. make
4. make install
5. Update /opt/koha/etc/koha-httpd.conf to use the same ports as in
 /etc/apache2/sites-enabled/kohadev.conf
6. sudo a2dissite kohadev.conf
7. sudo cp /opt/koha/etc/koha-httpd.conf /etc/apache2/sites-enabled/koha-httpd.conf
8. Copy any important details (like DB details) from 
 /etc/koha/sites/kohadev/koha-conf.xml to /opt/koha/etc/koha-conf.xml
9. Add following to VirtualHosts in /etc/apache2/sites-enabled/koha-httpd.conf
    <Directory "/opt/koha">
    Require all granted
    </Directory>
10. sudo service apache2 restart
11a. Go to http://localhost:8081/cgi-bin/koha/acqui/acqui-home.pl 
 and click "Search" in the "Search vendors" area
11b. Note the UI eventually loads
12. Enable the syspref ERMModule
13. Go to http://localhost:8081/cgi-bin/koha/mainpage.pl
14. Click on "E-resource management"
15. Note that the ERM interface eventually loads
16. Enable the syspref PreservationModule
17. Go to http://localhost:8081/cgi-bin/koha/mainpage.pl
18. Click on "Preservation"
19. Note the UI eventually loads
20. Go to http://localhost:8081/cgi-bin/koha/admin/admin-home.pl
21. Click on "Record sources"
22. Note the UI eventually loads
Comment 12 David Cook 2025-11-07 05:02:40 UTC
Good catch, Vivek, and thanks for the patch.
Comment 13 Marcel de Rooy 2025-11-07 08:12:54 UTC
Created attachment 189252 [details] [review]
Bug 41167: Fix missing rewrite rules in koha-httpd.conf

This patch adds missing RewriteRules for ERM, Preservation and Acquisition modules in koha-httpd.conf to restore staff client functionality.

Test plan:
1. Apply patch
2. Restart Apache
3. Access acquisitions and ERM pages
4. Confirm functionality restored

Signed-off-by: Vivek Kumar <vivek.kumar@bestbookbuddies.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>

Bug 41167: (follow-up) Correct rewrite rules in koha-httpd.conf

This follow-up patch fixes issues from the initial patch for Bug 41167:
- Adds missing asterisks (*) in rewrite rule patterns
- Removes erroneous RewriteRules from the OPAC virtualhost
- Ensures all ERM, Preservation, and Acquisition rewrite rules are correctly placed under the intranet virtualhost

Test plan:
1. Apply patch
2. Restart Apache
3. Access ERM, Preservation, and Acquisitions modules
4. Confirm pages load correctly without 404 or routing errors

Signed-off-by: Vivek Kumar <vivek.kumar@bestbookbuddies.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 14 Marcel de Rooy 2025-11-07 08:13:27 UTC
Squashed them now.
Comment 15 Jonathan Druart 2025-11-14 11:39:55 UTC
Created attachment 189595 [details] [review]
Bug 41167: Add test to compare both apache conf

Patch from commit 6df0f48
Comment 16 Jonathan Druart 2025-11-14 11:40:52 UTC
Marcel, David, I've written a quick test for this, but it fails:

The following line is in the debian version, not in koha-httpd.conf, is that correct?

# RewriteRule ^/cgi-bin/koha/(C4|debian|docs|etc|installer/data|install_misc|Koha|misc|selenium|t|test|tmp|xt)/|\.PL$ /notfound [PT]
Comment 17 Marcel de Rooy 2025-11-17 07:10:49 UTC
(In reply to Jonathan Druart from comment #16)
> Marcel, David, I've written a quick test for this, but it fails:
> 
> The following line is in the debian version, not in koha-httpd.conf, is that
> correct?
> 
> # RewriteRule
> ^/cgi-bin/koha/(C4|debian|docs|etc|installer/
> data|install_misc|Koha|misc|selenium|t|test|tmp|xt)/|\.PL$ /notfound [PT]

That is forgotten in httpd.conf. Doesnt hurt there too.
Comment 18 Marcel de Rooy 2025-11-17 08:07:26 UTC
xt/check_apache_conf.t .. Can't locate Data/Printer.pm in @INC
Comment 19 Marcel de Rooy 2025-11-17 08:24:32 UTC
(In reply to Marcel de Rooy from comment #18)
> xt/check_apache_conf.t .. Can't locate Data/Printer.pm in @INC

Will remove it.
Comment 20 Marcel de Rooy 2025-11-17 09:31:00 UTC
Created attachment 189626 [details] [review]
Bug 41167: Fix missing rewrite rules in koha-httpd.conf

This patch adds missing RewriteRules for ERM, Preservation and Acquisition modules in koha-httpd.conf to restore staff client functionality.

Test plan:
1. Apply patch
2. Restart Apache
3. Access acquisitions and ERM pages
4. Confirm functionality restored

Signed-off-by: Vivek Kumar <vivek.kumar@bestbookbuddies.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>

Bug 41167: (follow-up) Correct rewrite rules in koha-httpd.conf

This follow-up patch fixes issues from the initial patch for Bug 41167:
- Adds missing asterisks (*) in rewrite rule patterns
- Removes erroneous RewriteRules from the OPAC virtualhost
- Ensures all ERM, Preservation, and Acquisition rewrite rules are correctly placed under the intranet virtualhost

Test plan:
1. Apply patch
2. Restart Apache
3. Access ERM, Preservation, and Acquisitions modules
4. Confirm pages load correctly without 404 or routing errors

Signed-off-by: Vivek Kumar <vivek.kumar@bestbookbuddies.com>
Signed-off-by: David Cook <dcook@prosentient.com.au>

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 21 Marcel de Rooy 2025-11-17 09:31:02 UTC
Created attachment 189627 [details] [review]
Bug 41167: Add test to compare both apache conf

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
[EDIT] chmod 755, shebang, remove Data::Printer, enable NoWarnings
       one regex delimiter; replaced a grep by a map
Comment 22 Marcel de Rooy 2025-11-17 09:31:04 UTC
Created attachment 189628 [details] [review]
Bug 41167: Add missing line to etx/koha-httpd.conf

Test plan:
Run xt/check_apache_conf.t again. Should pass now.

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 23 Marcel de Rooy 2025-11-17 09:32:21 UTC
Resolved

[FAIL] xt/check_apache_conf.t
   FAIL   critic
                Don't modify $_ in list functions at line 32, column 9.  See page 114 of PBP.  (Severity: 5)
Comment 24 Lucas Gass (lukeg) 2025-11-17 22:17:08 UTC
Nice work everyone!

Pushed to main for 25.11
Comment 25 Paul Derscheid 2025-11-25 16:31:34 UTC
Nice work everyone!

Pushed to 25.05.x
Comment 26 Fridolin Somers 2025-12-02 11:14:37 UTC
Pushed to 24.11.x for 24.11.11

With a patch to not add rewrites for vendor