Removing index.php from the Nextcloud URI

Hi there,

I’ve seen this topic of removing index.php from Nextcloud address discussed in a few older [and now closed] threads already, but I don’t seem to be able to find a solid and final solution anywhere. That is why I’m posting this question again, despite it being discussed before. Is there an actual solution for this?

The relevant information:

Nextcloud version (12.0.0):
Operating system and version (CentOS 6):
Apache or nginx version (Apache 2.2.32):
PHP version (7.0.12):

I can also tel you that as far as I can see in my .htaccess, mod_env and mod_rewrite seem to be enabled. And I use a shared host at the moment [Bluehost]. And FastCGI is enabled.

I’d appreciate any solutions you can suggest.

Cheers!

1 Like

This works on CentOS 7!

Add this to your config.php

'htaccess.RewriteBase' => '/' (Path depends on your configuration - maybe /nextcloud)

Update htaccess with the occ command
sudo -u apache php occ maintenance:update:htaccess

Make sure all modules are enabled with
cat /etc/httpd/conf.modules.d/* | grep mod_env
and
cat /etc/httpd/conf.modules.d/* | grep mod_rewrite

The output line should not start with #

I also restarted my httpd
systemctl restart httpd

4 Likes

Thanks for your response,

I have added 'htaccess.RewriteBase' => '/' to config.php, and I’m sure both modules are enabled.
However using a shared host I do not have sudo rights. What should my .htaccess look like after this?

I compared my .htaccess with the current file from github…

This was added:

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} !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/.*
  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>

You can try it but without guarantee :wink:

3 Likes

Thanks! =) Tried adding this to .htaccess, doesn’t look like it’s made a different though.
Any other ideas?

Oh haha I just figured it out! It was in fact the bloody FastCGI… mod_php isn’t actually enabled when using FastCGI. I switched to php.ini and problem solved.

I’ve seen this question several times around the web, I hope someone else can use this.

Cheers!

I’m not sure if it is the right way to do it. But, I have added the below lines in the nextcloud.conf file under <Directory /var/www/nextcloud/> apart from occ update command

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

This worked for me. But it may not be useful if nextcloud is installed in a shared hosting

Hi
I do not understand the solution
where to switch what

can I get a detailed explanation for dummy

sorry for necrobumping this thread, but it may help others, facing the same problem:

  • mod_env enabled
  • mod_rewrite enabled
  • in config.php: 'htaccess.RewriteBase' => '/',
  • .htaccess was successfully written by occ maintenance:update:htaccess

but still having /index.php/

i was able to “quickfix” this by setting 'htaccess.IgnoreFrontController' => true in my config.php (see: Apache rewrite to remove index.php)

but finally, after some investigation, i found the “real” cause: nextcloud is not detecting working mod_env when php-fpm was running as fcgi !

background: with php running as cgi, every request was served via redirect which adds REDIRECT_ to all the variable-names set by SetEnv, like:

SetEnv front_controller_active true

becomes: [REDIRECT_front_controller_active] => true

it seems the nextcloud-check does not take this into account.

the proper solution was enabling the apache Module proxy_fcgi and changing the SetHandler like this:

<FilesMatch "\.php[345]?$">
         SetHandler "proxy:unix:/var/lib/php7-fpm/cloud.sock|fcgi://localhost"
</FilesMatch>

i also removed the lines for Action, Alias, and FastCgiExternalServer regarding the former php7-fcgi handler as they were no longer used.

and voila! the variablenames set via SetEnv in .htaccess stay unchanged, nextcloud recognises the front_controller_active variable -> /index.php/ is gone, without setting htaccess.IgnoreFrontController

1 Like

I spent some time trying to find where the issue come from.

As my nextcloud is in a specific folder, I had the following configuration in my apache2.

<Directory /home/mynextcloud>
	Options Indexes FollowSymLinks
	AllowOverride None
	Require all granted
</Directory>

I just set AllowOverride to

AllowOverride All

And fixed the problem.

@clouduser adding the line to my config.php and updating the htaccess worked for me. I didn’t even need to restart the server (I can’t anyway because I am on web hosting). Cheers!

Hi,

Since you are also a web user, could you explicitly name all of the steps that you have gone through? Specifically, it would be useful for me where you have installed your nextcloud (e.g. domain.com/nextcloud) and then explicitly mention the changes to the config.php file and .htaccess file and at what points during the installation process you have made them. That would be much appreciated!

1 Like

Hi, same problem for me. In my case: dummy mode.

Cheers
DM

@Tomvanwaas and @DadeMurphy

The solutions mentioned above can also be found in the nextcloud docs: Proxy Configurations

  1. Add this line to [root folder of nextcloud]/config/config.php:

'htaccess.RewriteBase' => '/',

Advice on parameter:

In a standard Apache setup this usually equals the folder that Nextcloud is accessible at. So if Nextcloud is accessible via “https://mycloud.org/nextcloud” the correct value would most likely be “/nextcloud”. If Nextcloud is running under “https://mycloud.org/” then it would be “/”.

  1. Login to your server via SSH and navigate to your nextcloud folder

  2. Run the following command to update your .htaccess file:
    occ maintenance:update:htaccess
    (on my web hosting server I need to run it like this: php occ maintenance:update:htaccess)

You can update the .htcaccess file in nextcloud root folder manually but I only recommend that when you really know what you are doing.

If you don’t have access to your server via SSH, try running occ commands via web interface.

Let me know if this was clear enough. Cheers :grin:

2 Likes

Greetings!

What should I do if I get this error when I run this command?
image

2 Likes

Perhaps you use an old php version. Read this.

1 Like

I had the same problem on my Nextcloud instance (on o2switch), this is the only solution that worked. Thanks :slight_smile:

Thanks a lot. It worked for me even my NextCloud instance run in HestiaCP.