Pretty URLs not working (yet another topic)mod_php

Hello everybody!

Starting with the title, I am unable to make pretty urls on my nextcloud instantce.
I am running:
Nextcloud version: 28.0.6
Operating system and version: Ubuntu 20.04.6 LTS
Apache or nginx version: Apache/2.4.41
PHP version: PHP 8.3.7
Apache 2 mod_php (NOT php-fpm)
mod env and rewrite are enabled.
config.php:

'overwrite.cli.url' => 'https://my.domain.com/',
'htaccess.RewriteBase' => '/',

file permissions on .htaccess are correct, it gets populated when running sudo -u **** php occ maintenance:update:htaccess with

ErrorDocument 403 /index.php/error/403
ErrorDocument 404 /index.php/error/404
<IfModule mod_rewrite.c>
  Options -MultiViews
  RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]
  RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]
  RewriteCond %{REQUEST_FILENAME} !\.(css|js|mjs|svg|gif|png|html|ttf|woff2?|ico|jpg|jpeg|ma>
  RewriteCond %{REQUEST_FILENAME} !/core/ajax/update\.php
  RewriteCond %{REQUEST_FILENAME} !/core/img/(favicon\.ico|manifest\.json)$
  RewriteCond %{REQUEST_FILENAME} !/(cron|public|remote|status)\.php
  RewriteCond %{REQUEST_FILENAME} !/ocs/v(1|2)\.php
  RewriteCond %{REQUEST_FILENAME} !/robots\.txt
  RewriteCond %{REQUEST_FILENAME} !/(ocs-provider|updater)/
  RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
  RewriteCond %{REQUEST_FILENAME} !/richdocumentscode(_arm64)?/proxy.php$
  RewriteRule . index.php [PT,E=PATH_INFO:$1]
  RewriteBase /
  <IfModule mod_env.c>
    SetEnv front_controller_active true
    <IfModule mod_dir.c>
      DirectorySlash off
    </IfModule>
  </IfModule>
</IfModule>

Still, index.php is still used. I tried accessing the server through local ip and through reverse proxy handling ssl and certificate.

Any ideas what else to try? I already read through 6 threads here, but none have a definitve answer that would work on my setup.

Regards,
Noni.

Can you post your Apache VirtualHost config for your Nextcloud vhost?

And just to rule out the obvious: Apache has been fully restarted since enabling the various modules?

Hello!
nexctloud.comf vhost file:

<VirtualHost *:80>
  DocumentRoot /var/www/html/
  ServerName  my.domain.com

  <Directory /var/www/html>
    Require all granted
    AllowOverride All
    Options +FollowSymLinks -MultiViews
    Satisfy Any
    <IfModule mod_dav.c>
      Dav off
    </IfModule>
  </Directory>
</VirtualHost>

a2ensite nextcloud.conf

Yes, the Apache server has been restarted. In the last 2 days I have been trying a few tutorials and forum posts, I have restarted the hell out of it.

I do not know why this information is not more readily available. It is a very important piese of information, needed for any modifications brought into .htaccess file.
Posted by @Oblivion here: The "Strict-Transport-Security" HTTP header is not set to at least "15552000" seconds. For enhanced security, it is recommended to enable HSTS - #26 by justyoshi, he mentions:

.htaccess needs to be enabled with AllowOverride
This is the first thing that should be verified. If the AllowOverride directive is set to None then this will disable all .htaccess files. In order to verify this, you must open the Apache configuration file (typically either called httpd.conf or apache.conf) and check that the AllowOverride directive is set to AllowOverride All. If you needed to make changes to your Apache config, remember to save the file and restart Apache. sudo service apache2 restart

Which means /etc/apache2/apache2.conf NEEDS to have AllowOverride All under <Directory /var/www/>.
Good piese of information and advice, thanks to Oblivion. This really needs to be in the tutorial for installing Nextcloud. At least as a verification on things not working with .htaccess configs.

I’m glad you got things working, but I’ve re-looked at the documentation this morning (and also did some testing to confirm in case the docs need an update). I obviously believe you that you got it working, but I think something else may be going on here…

It’s true that using an .htaccess file requires AllowOverride All to be active either at the same level or above as where the .htaccess is located. But there is no need to do AllowOverride All above the webroot (/var/www/html). If you need to do so for /var/www it means the config in your nextcloud.conf is not being used or itself is being override for some reason (though there’s nothing technically wrong with doing it there instead). It’s more of an “either/or” situation.

Your situation is somewhat documented in the Troubleshooting section: General troubleshooting — Nextcloud latest Administration Manual latest documentation

For the first case the .htaccess file shipped with Nextcloud should do this work for you when you’re running Apache. You need to make sure that your Web server is using this file. Additionally, you need the mod_rewrite Apache module installed and AllowOverride All set in your apache2.conf or vHost-file to process these redirects.

Are you certain you don’t have overlapping VirtualHost’s or something like that? They may be in entirely different config files. Maybe do this:

grep -r AllowOverride /etc/apache2
grep -r "/var/www" /etc/apache2
1 Like

These days I just reinstalled apache and php from scratch, with apt remove --purge... commands for these packages, and reconfigured them as per the instructions. The issue is that - as I understand it - if apache2.conf has AllowOverride None on the webroot directoy or above, it will simply not take into consideration the nextcloud.conf file when a2ensite nextcloud.conf is used. Not to mention, .htacces will definetly not be taken into consideration. As you can see, my nextcloud.conf did have the AllowOverwrite directive entered. So, no idea why that did not take effect when using ensite command.
grep -r AllowOverride /etc/apache2:

/etc/apache2/mods-available/userdir.conf:               AllowOverride FileInfo AuthConfig Limit Indexes
/etc/apache2/mods-available/alias.conf:         AllowOverride None
/etc/apache2/apache2.conf:      AllowOverride None
/etc/apache2/apache2.conf:      AllowOverride None
/etc/apache2/apache2.conf:      AllowOverride All
/etc/apache2/apache2.conf:#     AllowOverride None
/etc/apache2/apache2.conf:# for additional configuration directives.  See also the AllowOverride
/etc/apache2/sites-available/nextcloud.conf:    AllowOverride All
/etc/apache2/sites-available/nextcloud.conf.http:    AllowOverride All
/etc/apache2/conf-available/serve-cgi-bin.conf:                 AllowOverride None
/etc/apache2/conf-available/security.conf:#   AllowOverride None

grep -r “/var/www” /etc/apache2:

/etc/apache2/apache2.conf:# not allow access to the root filesystem outside of /usr/share and /var/www.
/etc/apache2/apache2.conf:<Directory /var/www/>
/etc/apache2/sites-available/nextcloud.conf:  DocumentRoot /var/www/html/
/etc/apache2/sites-available/nextcloud.conf:  <Directory /var/www/html>
/etc/apache2/sites-available/nextcloud.conf.http:  DocumentRoot /var/www/html/
/etc/apache2/sites-available/nextcloud.conf.http:  <Directory /var/www/html/>
/etc/apache2/sites-available/default-ssl.conf:          DocumentRoot /var/www/html
/etc/apache2/sites-available/000-default.conf:  DocumentRoot /var/www/html

Does /etc/apache2/sites-enabled contain anything other than nextcloud.conf?

For example, it would possibly be overridden if it happens to include 000-default.conf or nextcloud.conf.http (whatever that file is) and the VirtualHost entries overlap?

Yes, those are all files available in sites-available folder. default-ssl and 000-default are the stock files, but I did use a2dissite for both of them, just to be sure, with a2dissite.

Please share the output of the following:

apache2ctl -t -C "LoadModule info_module /usr/lib/apache2/modules/mod_info.so" -D DUMP_CONFIG | grep -vE "^[ ]*#[ ]*[0-9]+:$"

It provides the fully parsed output of all of your combined Apache configuration files.

(Note to anyone else that reads this: the path to mod_info is different under different distributions).