Is the .htaccess in the repository out of date?

Here is what I’ve done to install NextCloud by migrating from ownCloud:

  • Clone NextCloud version v9.0.52 into a new directory and initialize submodules in the 3rd party subdirectory
  • Copy the config.php from the ownCloud installation
  • The data directory remained untouched as it was outside the web root already
  • Finally run ./occ upgrade

All went well and I’m now a happy user of NextCloud. Bye bye ownCloud.

Then, what I noticed was that my git status was dirty. With a git diff I found out what’s the difference:

diff --git a/.htaccess b/.htaccess
index 5bf7b32..69742ec 100644
--- a/.htaccess
+++ b/.htaccess
@@ -72,3 +72,32 @@ Options -Indexes
 <IfModule pagespeed_module>
   ModPagespeed Off
 </IfModule>
+#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####
+
+ErrorDocument 403 /core/templates/403.php
+ErrorDocument 404 /core/templates/404.php
+<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} !/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} !/updater/
+  RewriteCond %{REQUEST_FILENAME} !/ocs-provider/
+  RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*
+  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>

So it looks like the upgrade process has modified the .htaccess file from the git repository and if that’s true I wonder if that modification should already be included in the repository.

Not sure about the rewrite part, could be an issue with your installation. But the ErrorDocument entries have always been not committed.

Interesting. So are there installations where those instructions are not required? In other words, are they conditional? And if so, what are the conditions that are causing this?

I’m asking because it is some part of the NextCloud package that is writing these into the .htaccess and not anything else.

If this is really configuration specific, then the .htaccess should be added to the .gitignore file, shouldn’t it?

I’m also wondering if this may have anything to do with all of the people reporting problems with their htaccess files failing the code check, too. I assumed that it was all just people copying the visible files and not the hidden ones, but I think (?) there was at least one where this wasn’t the case…

They’re created at setup time:

And regarding the other block, this happens when pretty URLs are enabled. It’s a bit strange that this is pasted below the “do not change anything above” line, so maybe that’s a bug.

No, the reason why it’s below the line is, that everything about the line is checked with the code checker and has a defined checksum. It’s a bit odd but that’s the situation. :unamused:

Ah yes, of course :slight_smile: