DietPi icon indicating copy to clipboard operation
DietPi copied to clipboard

Nextcloud Notes lighttpd url rewrite issue

Open neonblind opened this issue 2 months ago • 3 comments

opening: https://url.com/nextcloud/apps/notes/note/1001 redirects me to https://url.com/nextcloud/index.php/apps/notes/note/1010

1010 is the ID of the latest note created/edited. it seems it redirects to https://url.com/nextcloud/index.php/apps/notes which opens always the latest note.

using https://url.com/nextcloud/index.php/apps/notes/note/1001 does open the correct note

neonblind avatar Nov 08 '25 12:11 neonblind

Is Nextcloud itself probably redirecting that for some reason? The Lighttpd does not mess with that part of the URL 🤔:

url.rewrite-if-not-file += (
	"^/nextcloud/((core/ajax/update|cron|public|remote|status|ocs/v[12]|richdocumentscode(_arm64)?/proxy)\.php|ocs-provider/|updater/)" => "",
	"^/nextcloud(.*)" => "/nextcloud/index.php$1"
)

So it takes everything after /nextcloud path element and appends it after index.php. If a number within the trailing URL part changes for a single URL, but not in any other case, I guess Nextcloud for some reason does this. Or some weird caching issue. Maybe try to restart Lighttpd and PHP and clear browser data for that site.

But indeed the Lighttpd integration is not great, since Nextcloud internally generates index.php URLs for everything. I did not find a way to "tell" Nextcloud via Lighttpd that the rewrites are in place. Although I also did not have another look for a longer time. Generally, I recommend Apache for Nextcloud, since it is covered by the .htaccess configs they ship. Nginx has at least good community support. Regarding Lighttpd, I was moreless the only one trying to collect proper info about how to set it up with Nextcloud: https://help.nextcloud.com/t/23110

But at least proper caching rules can be added easily. Will turn this into an enhancement.

MichaIng avatar Nov 08 '25 14:11 MichaIng

Okay, for Nextcloud internal link URLs, it is theoretically pretty simple: Nextcloud just requires the environment variable front_controller_active to be set to true in PHP. Will test later, but something like that should do:

$HTTP["url"] =~ "^/nextcloud($|/)" {
  fastcgi.server = ( ".php" =>
    ((
      "socket" => "/run/php/php-fpm.sock",
      "broken-scriptfilename" => "enable"
      "bin-environment" => (
        "front_controller_active" => "true"
      )
    ))
  )
}

The problem is that the fastcgi.server = ( ".php" => handler is defined in the global config already, and Lighttpd does not seem to allow extending the existing handler with an "bin-environment" block. So we'd need to overwrite fastcgi.server entirely for the Nextcloud sub directory.

MichaIng avatar Nov 08 '25 15:11 MichaIng

"front_controller_active" => "true" did the trick. it completely removes index.php from the url and the correct note opens.

So we'd need to overwrite fastcgi.server entirely for the Nextcloud sub directory.

How does this work?

Adding "front_controller_active" => "true" in fastcgi-php-fpm.conf is working but adding

fastcgi.server = ( ".php" => (( "socket" => "/run/php/php-fpm.sock", "broken-scriptfilename" => "enable" "bin-environment" => ( "front_controller_active" => "true" ) )) )

in lighttpd.nextcloud.conf does nothing.

neonblind avatar Nov 09 '25 14:11 neonblind