Stop inserting "index.php" with Apache + fastcgi?

Hi everybody,

I am using Nextcloud 11.0.2 on Webfaction, and everything seem to work well. Now I would like to remove “index.php” from the URLs. I followed the instructions here and added 'htaccess.RewriteBase' => '/' to my config, however then I read:

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.

As far as I can see, Webfaction uses Apache with fastcgi and PHP 7. Nevertheless, the url rewriting seems to work. I can use either or However, often, but not always, I get a 303 redirect to the long url (with index.php). Also, some links (such as in the dropdown menu in the top left) have the long urls, and some others don’t.

Is there any way to suppress these redirects? It seems some part of the code is thinking the URL rewriting does not work, while it does. Any ideas?

found a solution? same problem here.

Have you also done a regeneration of the .htaccess file with the occ command:

sudo -u www-data php occ maintenance:update:htaccess

No I haven’t found a solution yet.

@StephanW Yes, the .htaccess file is generated properly. Redirects from short to long addresses work fine. The problem is that Nextcloud (unnecessarily) writes the long URLs into the HTML output.

You have the possibility to connect via SSH to your Webfaction server. Can you check which PHP packages are installed but running:

dpkg -l | grep php

And show the list of active Apache modules with:

ls /etc/apache/mods-enabled

As it states the mod_fastcgi is not supported, so the incoming requests (if you remove the index.php part) will work since the rewrite code will process it, but the outgoing HTML code won’t be changed since it can’t process it as per the documentation.

same problem here. jessie, php5.6, fpm. everything works except removing index.php from the url. even the urls without index.php work fluently, but nextlcoud constantly adds/redirects it to the links with index.php…

dpkg -l|grep php
ii  php-pear                       5.6.30+dfsg-0+deb8u1               all          PEAR - PHP Extension and Application Repository
ii  php5                           5.6.30+dfsg-0+deb8u1               all          server-side, HTML-embedded scripting language (metapackage)
ii  php5-cgi                       5.6.30+dfsg-0+deb8u1               amd64        server-side, HTML-embedded scripting language (CGI binary)
ii  php5-cli                       5.6.30+dfsg-0+deb8u1               amd64        command-line interpreter for the php5 scripting language
ii  php5-common                    5.6.30+dfsg-0+deb8u1               amd64        Common files for packages built from the php5 source
ii  php5-curl                      5.6.30+dfsg-0+deb8u1               amd64        CURL module for php5
ii  php5-dev                       5.6.30+dfsg-0+deb8u1               amd64        Files for PHP5 module development
ii  php5-fpm                       5.6.30+dfsg-0+deb8u1               amd64        server-side, HTML-embedded scripting language (FPM-CGI binary)
ii  php5-gd                        5.6.30+dfsg-0+deb8u1               amd64        GD module for php5
ii  php5-imagick                   3.2.0~rc1-1                        amd64        Provides a wrapper to the ImageMagick library
ii  php5-imap                      5.6.30+dfsg-0+deb8u1               amd64        IMAP module for php5
ii  php5-intl                      5.6.30+dfsg-0+deb8u1               amd64        internationalisation module for php5
ii  php5-json                      1.3.6-1                            amd64        JSON module for php5
ii  php5-mcrypt                    5.6.30+dfsg-0+deb8u1               amd64        MCrypt module for php5
ii  php5-mysql                     5.6.30+dfsg-0+deb8u1               amd64        MySQL module for php5
ii  php5-sqlite                    5.6.30+dfsg-0+deb8u1               amd64        SQLite module for php5
ii  php5-xsl                       5.6.30+dfsg-0+deb8u1               amd64        XSL module for php5

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)
 actions_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 fastcgi_module (shared)
 filter_module (shared)
 headers_module (shared)
 mime_module (shared)
 mpm_worker_module (shared)
 negotiation_module (shared)
 reqtimeout_module (shared)
 rewrite_module (shared)
 rpaf_module (shared)
 setenvif_module (shared)
 status_module (shared)

apache virtual host like this

<VirtualHost *:80>

  DocumentRoot /var/www/nextcloud/foo
  <Directory /var/www/nextcloud/foo>
    Options +FollowSymlinks
    AllowOverride All
    Require all granted
    Satisfy Any
   <IfModule mod_dav.c>
    Dav off
   SetEnv HOME /var/www/nextcloud/foo
   SetEnv HTTP_HOME /var/www/nextcloud/foo

  #we have our own fpm-user/pool:
  <IfModule mod_fastcgi.c>
      AddType application/x-httpd-fastphp5 .php
      Action application/x-httpd-fastphp5 /php5-fcgi
      Alias /php5-fcgi /usr/lib/cgi-bin/php5-fcgi-foo
      FastCgiExternalServer /usr/lib/cgi-bin/php5-fcgi-foo -socket /var/run/php5-fpm-foo.sock -pass-header Authorization

php fpm pool like this

user = www-foo
group = www-foo
listen = /var/run/php5-fpm-foo.sock
listen.owner = www-data = www-data
pm = dynamic
pm.max_children = 5
pm.start_servers = 3
pm.min_spare_servers = 1
pm.max_spare_servers = 3
pm.status_path = /status
ping.path = /ping
slowlog = /dev/null
request_slowlog_timeout = 30s
chdir = /
catch_workers_output = yes
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
security.limit_extensions =

nextcloud 11.0.2 with config

  'overwrite.cli.url' => '',
  'htaccess.RewriteBase' => '/',

generated .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|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

As can be seen in your output it shows it is using FastCGI, which is not supported for pretty URLs. The rewrite section in the .htaccess file will rewrite any ‘pretty’ incoming URLs to include index.php but the outgoing HTML code back to the browser won’t get rewritten to remove the index.php due to the restrictions of fastcgi and fpm. So unfortunately it won’t be possible unless you are able to switch over to the mod_php structure.

This isn’t a problem with NextCloud but a limitation of the interaction of Apache and PHP (for which only the mod_php can rewrite it).

Hi, my hoster uses CentOS and not Debian, but here are the packages:

$ rpm -qa | grep php70 | sort

$ ls /etc/apache/mods-enabled
ls: cannot access /etc/apache/mods-enabled: No such file or directory

$ ls /etc/httpd/modules                                                                                                                               

Here is a phpinfo, redirected to in the same way as index.php (which I will take down after a while):

The mod_rewrite part works absolutely fine. The problem is that nextcloud constructs URLs using SCRIPT_NAME (/phpinfo.php or /index.php), instead of SCRIPT_URL (/information/test or /apps/files). I wasn’t able to find the place in the source where that happens, as it goes through many layers of indirection.

I have to add that some links are correct (like the left-hand sidebar, All Files, Recent, …). Some links are not supposed to be shortened (remote.php). But most links that could be shortened are not. And I find that I sometimes, but not always, get redirected to the long URL. The redirect seems to get issued from PHP, not Apache.

Thanks for helping!

Hi StephanW,
I heard that before, could you please elaborate a bit? PHP code can write any URL it likes into HTML, I don’t understand how this can be a restriction from fastcgi. I thought maybe the issue was fastcgi not reporting the correct “clean” URL to PHP, but in my tests all the clean path, the original path, and the query parameters were available.

It seems to be rather a problem with the routing code or Symfony not detecting that short URLs are available. Somewhere in these files maybe?


My last experience with PHP is a long time ago so this is not so easy :slight_smile: but I think maybe I can at least create a config option to force short URLs.

You are correct in regards to the URLGenerator.php file, this does check if it can generate pretty URLs.

The line of code that checks for it is:

$frontControllerActive = ($this->config->getSystemValue('htaccess.IgnoreFrontController', false) === true || getenv('front_controller_active') === 'true');

But am not sure exactly where the FrontController values come from, but if you follow that script you can see it uses an if/else to use the index.php or pretty URL.

hm. not sure if i’m right: isn’t that a bug in the if? IgnoreFrontController===true means $frontControllerActive = true. as far as i understand $frontControllerActive should be false, if IgnoreFrontController===true… (if we keep out the ENV-var)… the default for this option is false … i don’t know if this matters at all on the whole discussion.

i found a solution (need to test further)… adding
'htaccess.IgnoreFrontController' => true,
to the config file works. as far as i see there is no change to the .htaccess when ./occ maintenance:update:htaccess is called…

but not sure what other consequences this option has…

1 Like

Thanks StefanW, toastbrotch, that is really interesting! I think this should be investigated further though to see that nothing breaks (e.g. infinite redirect loops). If it works, then it is just a matter of fixing the detection and I might be able to write a patch!

Edit: it seems front_controller_active is set in .htaccess by mod_env, which doesn’t work with fastcgi (I think because it reuses the same process, it cannot inject environment variables between calls). So this is just a matter of not detecting mod_rewrite. I have to think about it a bit more, probably this could be done in a different way.

About IgnoreFronController, this seems to be fairly benign, and is documented here:


1 Like

Yes you are correct. By default it will check if there is a front controller, but if (for example described in your link reference) it isn’t possible to confirm it, you can overwrite it by setting that value, as long as you can confirm yourself that mod_rewrite is working as expected.

So steps would be:

  1. Confirm rewrite is active and working
  2. Disable FrontController in config.php
  3. Confirm pretty URLs are working

yep on my setup:

  1. mod_rewrite is active and working
  2. setting: ‘htaccess.IgnoreFrontController’ => true in the config.php gives pretty urls

in the documentation is also ‘overwritewebroot’ => ‘’ mentioned, but this has no effect (i dont know if it should in our setups)

I would say if it works without setting ‘overwritewebroot’ then it won’t effect it and will be obsolete to use.

Only if there are problems (behind a proxy) you would want to set that value.

jup. i’m behind a proxy (nginx with ssl-offloading)… now everything works perfect. thanx!!

I am now myself hitting this issue.

I checked the lib/private/URLGenerator.php file (by checking the variables and outputting $urlLinkTo variable) and found that the URL is correct ‘/’ only. But the end HTML still includes the index.php part. So now puzzled where this is being added.

Are you using a Self Signed Certificate? I also followed this instructions Remove /index.php/ from the url until I realized I was using the SSL website so I just add the code to the apache virtual host, in my case nextcloud-ssl.conf

config.php file:

<?php $CONFIG = array ( 'htaccess.RewriteBase' => '/', Apache for both virtual hosts: Options +FollowSymlinks AllowOverride All Dav off SetEnv HOME /var/www/nextcloud SetEnv HTTP_HOME /var/www/nexcloud Satisfy Any

I don’t use self-signed certifcates. I have those lines already in my vhost config, as per the installation procedure.

I did notice that the only place the ‘index.php’ is showing is in the files section. Any other app or menu item is using pretty URL.