[Solved] Can't get pretty URLs to work

NextCloud 14.0.1(.1?), Ubuntu 18.04.1, Apache 2.4.29, PHP 7.2.10-0

I’ve been all over the documentation, the forum, and github trying to get pretty URLs working.

With this in my config.php (as per the documentation):

<?php
$CONFIG = array (
  'overwrite.cli.url' => 'https://cloud.mydomain.com',
  'htaccess.RewriteBase' => '/',

when I run

sudo -u www-data ./occ maintenance:update:htaccess

I get the error:

Error updating .htaccess file, not enough permissions or "overwrite.cli.url" set to an invalid URL?

Based on 14.0.0 maintenance:update:htaccess fails, I added a trailing slash to the overwrite.cli.url setting. With this, the command succeeds and the timestamp for .htaccess changes, so that appears to be successful … however, after a

sudo systemctl restart apache2

nothing changes; the sharing URLs (and all the other URLs, for that matter) still have index.php in them.

For the sake of completeness:

Permissions on .htaccess are:

$ ls -la .htaccess
-rwxrwx--- 1 www-data www-data 3951 Oct  8 23:57 .htaccess

The end of .htaccess looks like this:

#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 /
ErrorDocument 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|svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$
  RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$
  RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$
  RewriteCond %{REQUEST_FILENAME} !/remote.php
  RewriteCond %{REQUEST_FILENAME} !/public.php
  RewriteCond %{REQUEST_FILENAME} !/cron.php
  RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php
  RewriteCond %{REQUEST_FILENAME} !/status.php
  RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php
  RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php
  RewriteCond %{REQUEST_FILENAME} !/robots.txt
  RewriteCond %{REQUEST_FILENAME} !/updater/
  RewriteCond %{REQUEST_FILENAME} !/ocs-provider/
  RewriteCond %{REQUEST_URI} !^/\.well-known/(acme-challenge|pki-validation)/.*
  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>

(There are 80 lines above that, and as far as I can tell they looks like everyone else’s.)

Apache modules are:

$ apachectl -M
Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 evasive20_module (shared)
 filter_module (shared)
 headers_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php7_module (shared)
 qos_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 socache_shmcb_module (shared)
 ssl_module (shared)
 status_module (shared)
1 Like

The problem turned out to be that Apache wasn’t configured to read .htaccess. When I added:

  <Directory /var/www/nextcloud>
    Options +FollowSymlinks
    AllowOverride All
  </Directory>

to my Apache config file, it started working.

5 Likes