Apache reverse proxy not working with query params

I would like to set up a reverse proxy that serves only one shared nextcloud folder. I figured out that when I navigate through nextcloud shared folders, as a guest, the URL looks something like this:


So, I would like my.example.com to be a proxy for (roughly) …/nextcloud/index.php/s/5ZPabR7diCxyJZk?path=$1

I had this working at one time, with an older version of nextcloud, but my disk crashed, and I lost some of my config files. I’ve rebuilt from scratch, with a new version of Nextcloud (on Fedora 39), but I can’t get this working again. What’s happening now is that the subpaths are lost. Every URL I try, e,g, my.example.com/subpath1/subpath2 lands me in the main folder that I shared in nextcloud. The ?path=subpath1/subpath2 part has been lost. I can continue to navigate my.example.com and get where I want to go, but I’d really like the deep links to work properly.

Here’s what my virtual host file looks like now:

<VirtualHost *:80>
    ServerName my.example.com

    # ProxyPass for requests not starting with /nextcloud
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !^/nextcloud [NC]
    RewriteRule (.*)$1 [P]

This is what my /etc/nextcloud/config.php file looks like

$CONFIG = array (
  'log_type' => 'syslog',
  'datadirectory' => '/var/lib/nextcloud/data',
  'updatechecker' => false,
  'check_for_working_htaccess' => false,
  'asset-pipeline.enabled' => false,
  'assetdirectory' => '/var/lib/nextcloud',
  'preview_libreoffice_path' => '/usr/bin/libreoffice',
  'apps_paths' =>
  array (
    0 =>
    array (
      'path' => '/usr/share/nextcloud/apps',
      'url' => '/apps',
      'writable' => false,
    1 =>
    array (
      'path' => '/var/lib/nextcloud/apps',
      'url' => '/apps-appstore',
      'writable' => true,
  'instanceid' => '<snip>'
  'passwordsalt' => '<snip>',
  'secret' => '<snip>',
  'trusted_domains' =>
  array (
    0 => 'localhost',
    1 => '',
    2 => 'my.example.com',
  'dbtype' => 'sqlite3',
  'version' => '',
  'overwrite.cli.url' => 'http://localhost/nextcloud',
  'installed' => true,
  'theme' => '',
  'loglevel' => 2,
  'maintenance' => false,

Any suggestions for how to debug this? I’ve tried logging the rewrite engine output, with “LogLevel debug rewrite:trace1 proxy_fcgi:trace1 proxy:trace1”, and as best I can tell, at some point the query params get lost.


Nextcloud version : 28.0.4
Operating system and version : Fedora 39
Apache version : 2.4.5
PHP version: 8.2.18

BTW, updating the RewriteRule to remove the [P] gives me the behavior I expect - the URL is rewritten to It’s something fish about the proxy setup.