Pretty urls not working after migration/confused by two .htaccess files

I’m not able to get pretty URLs following the instructions.

Nextcloud version (eg, 12.0.2): 13.0.4
Operating system and version (eg, Ubuntu 17.04): Debian 4.9.88-1
Apache or nginx version (eg, Apache 2.4.25): Apache 2.4.25
PHP version (eg, 7.1): 7.0.27-0+deb9u1

Is this the first time you’ve seen this error? (Y/N): yes, after migration

after migration my browser does not display “pretty urls”. Instead it displays something like that:

https://schreibauf.de/owncloud/index.php/apps/files/?dir=/Rezepte&fileid=53050

Please don’t be confused about “owncloud” at the end. The reason is, that I have some clients using that url in lot of apps.

So index.php is still displayed.

Steps to replicate it:

  1. I put this lines into the config.php

    ‘overwrite.cli.url’ => ‘https://schreibauf.de/owncloud’,
    ‘htaccess.RewriteBase’ => ‘/owncloud’,

  2. I launched this command:

    sudo -u www-data php /var/www/owncloud/occ maintenance:update:htaccess

  3. I restarted apache and and cache:

    sudo systemctl restart php7.0-fpm
    sudo systemctl restart apache2

The output of your Nextcloud log in Admin > Logging:

Console command executed: maintenance:update:htaccess

The output of your config.php file in /path/to/nextcloud (make sure you remove any identifiable information!):

<?php
$CONFIG = array (
  'instanceid' => 'yyy',
  'passwordsalt' => 'xxx',
  'datadirectory' => '/var/oc-data',
  'version' => '13.0.4.0',
  'dbtype' => 'mysql',
  'dbname' => 'yyz',
  'dbuser' => 'xyz',
  'dbpassword' => 'xyz',
  'dbhost' => 'localhost',
  'dbtableprefix' => 'oc_',
  'installed' => true,
  'loglevel' => 0,
  'theme' => '',
  'maintenance' => false,
  'trusted_domains' =>
  array (
    0 => 'schreibauf.de',
    1 => 'benjaminbruecker.de',
  ),
  'secret' => 'xxx',
  'memcache.local' => '\\OC\\Memcache\\APCu',
  'trashbin_retention_obligation' => 'auto',
  'updatechecker' => false,
  'appstore.experimental.enabled' => true,
  'overwrite.cli.url' => 'https://schreibauf.de/owncloud',
  'htaccess.RewriteBase' => '/owncloud',
  'updater.secret' => 'xx',
);

The output of your Apache/nginx/system log in /var/log/____:

no erros logged

I’m confused about two .httacces files in my set-up. Both seems to be created or at least edited by some nextcloud processes. Btw. both are writeable for the server.

Here is the file of the nextcloud config (/var/www/owncloud/.htaccess):

<IfModule mod_headers.c>
  <IfModule mod_setenvif.c>
    <IfModule mod_fcgid.c>
       SetEnvIfNoCase ^Authorization$ "(.+)" XAUTHORIZATION=$1
       RequestHeader set XAuthorization %{XAUTHORIZATION}e env=XAUTHORIZATION
    </IfModule>
    <IfModule mod_proxy_fcgi.c>
       SetEnvIfNoCase Authorization "(.+)" HTTP_AUTHORIZATION=$1
    </IfModule>
  </IfModule>

  <IfModule mod_env.c>
    # Add security and privacy related headers
    Header set X-Content-Type-Options "nosniff"
    Header set X-XSS-Protection "1; mode=block"
    Header set X-Robots-Tag "none"
    Header set X-Download-Options "noopen"
    Header set X-Permitted-Cross-Domain-Policies "none"
    SetEnv modHeadersAvailable true
  </IfModule>

  # Add cache control for static resources
  <FilesMatch "\.(css|js|svg|gif)$">
    Header set Cache-Control "max-age=15778463"
  </FilesMatch>

  # Let browsers cache WOFF files for a week
  <FilesMatch "\.woff$">
    Header set Cache-Control "max-age=604800"
  </FilesMatch>
</IfModule>
<IfModule mod_php5.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 512M
  php_value mbstring.func_overload 0
  php_value always_populate_raw_post_data -1
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>
<IfModule mod_php7.c>
  php_value upload_max_filesize 511M
  php_value post_max_size 511M
  php_value memory_limit 512M
  php_value mbstring.func_overload 0
  php_value default_charset 'UTF-8'
  php_value output_buffering 0
  <IfModule mod_env.c>
    SetEnv htaccessWorking true
  </IfModule>
</IfModule>
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_USER_AGENT}  DavClnt
  RewriteRule ^$         /remote.php/webdav/          [L,R=302]
  RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
  RewriteRule ^\.well-known/host-meta /public.php?service=host-meta [QSA,L]
  RewriteRule ^\.well-known/host-meta\.json /public.php?service=host-meta-json [QSA,L]
  RewriteRule ^\.well-known/carddav /remote.php/dav/ [R=301,L]
  RewriteRule ^\.well-known/caldav /remote.php/dav/ [R=301,L]
  RewriteRule ^remote/(.*) remote.php [QSA,L]
  RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
  RewriteCond %{REQUEST_URI} !^/.well-known/(acme-challenge|pki-validation)/.*
  RewriteRule ^(?:\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
</IfModule>
<IfModule mod_mime.c>
  AddType image/svg+xml svg svgz
  AddEncoding gzip svgz
</IfModule>
<IfModule mod_dir.c>
  DirectoryIndex index.php index.html
</IfModule>
AddDefaultCharset utf-8
Options -Indexes
<IfModule pagespeed_module>
  ModPagespeed Off
</IfModule>
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 /owncloud/
ErrorDocument 404 /owncloud/
<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 /owncloud
  <IfModule mod_env.c>
    SetEnv front_controller_active true
    <IfModule mod_dir.c>
      DirectorySlash off
    </IfModule>
  </IfModule>
</IfModule>

The file has the time stamp, when I was running the occ maintenance:update:htaccess command. So not created by myself.

And here is the .httaccess in my data directory (/var/oc-data/.htaccess):

# Generated by Nextcloud on 2018-06-20 12:13:36
# line below if for Apache 2.4
<ifModule mod_authz_core.c>
Require all denied
</ifModule>

# line below if for Apache 2.2
<ifModule !mod_authz_core.c>
deny from all
Satisfy All
</ifModule>

# section for Apache 2.2 and 2.4
<ifModule mod_autoindex.c>
IndexIgnore *
</ifModule>

The time stamp in the file is when I was perfoming an update.

Maybe something wrong with the host config?

Alias /owncloud "/var/www/owncloud/"
<IfModule mod_headers.c>
      Header always set Strict-Transport-Security "max-age=15552000; includeSubDomains; preload"
</IfModule>

Protocols h2 http/1.1

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

 <IfModule mod_dav.c>
  Dav off
 </IfModule>

 SetEnv HOME /var/www/owncloud
 SetEnv HTTP_HOME /var/www/owncloud

</Directory>

I don’t know, why and how I got those two .htaccess. Any explanetions?

So what I tried:

  1. I removed the /var/oc-data/.htaccess file (always: restarted php7.0-fpm & apache2 before, cleaned browser cache, and logged in): still index.php in the url.
  2. I copied /var/www/owncloud/.htaccess to /var/oc-data/.htaccess: still index.php in the url.

From my point of view, more attempts are just guessing around. Before I try something else, I would like to know, what is wrong.

One of the differences to the old system, is that I now use php7.0-fpm instead of apache-php. Could that be the reason?

I found it by myself: the target in the directory directive was wrong. Now the .htaccess file is loaded.

1 Like

That was the exact same error I just made. Had renamed the directory :stuck_out_tongue: