1

I installed Nextcloud on my Webfaction web space, and want to remove the "index.php" in the URL. I followed the instructions here, but then realized that it says:

Furthermore these instructions are only working when using Apache together with the mod_php Apache module for PHP. Other modules like php-fpm or mod_fastcgi are unsupported.

It seems my hoster is using Apache with fastcgi. However, the clean URLs do work - instead of https://example.com/index.php/apps/files/, I can go to https://example.com/apps/files/ and get the correct page. But Nextcloud just goes ahead and inserts the "index.php" when I navigate around. To be precise, a 303 redirect to the long URL is issued.

Also, this forum entry suggests that it does work with php7 and fastcgi.

How can I get it to stop inserting that? I'm fine with editing the code if neccessary, but my experience with PHP is from the time of mysql_* APIs, and before classes, so I'm having a hard time finding my way around :-) - maybe somebody here already knows a quick fix for this problem.

2 Answers 2

0

Add these lines in Nextcloud's config/config.php:

  'htaccess.RewriteBase' => '/',
  'htaccess.IgnoreFrontController' => true,

Then run occ maintenance:update:htaccess from the console to update the .htaccess file.

You should see these lines added to the end of .htaccess:

<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|woff2?|ico|jpg|jpeg|map|webm|mp4|mp3|ogg|wav)$
  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_FILENAME} !/ocm-provider/
  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>

mod_rewrite and mod_env must be enabled on your server for this to work. You might have to restart the server for the changes to kick in.

This was successfully tested with a Nextcloud 20.0.4 (stable release) on a regular Web install.

3
  • What if the occ maintenance:update:htaccess command outputs the following in the console: -bash: occ: command not found i.stack.imgur.com/gYSJP.png
    – Andrey S
    Jul 5, 2021 at 19:34
  • @AndreyS First make sure to cd to the Nextcloud root dir. If it still fails, try php occ maintenance:update:htaccess (occ command is a PHP script). Aug 16, 2021 at 20:23
  • @AndreyS Also make sure you run occ as the web server process user, not as root. ls -l into Nextcloud root dir to show owner of the files. Under Apache, that would be www-data, so you would sudo su www-data before running occ. Aug 16, 2021 at 21:36
0

What if the occ maintenance:update:htaccess command outputs the following in the console: -bash: occ: command not found https://i.stack.imgur.com/gYSJP.png

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.