Htaccess for subfolder


How can I make nextcloud honor the .htaccess file in its subfolder?

If I place the htaccess in the root folder it will work without error messages in the automated check about webfinger, caldav etc…

But if I use the same htaccess in the subfolder only it will display errors.

Nextcloud is in a subfolder called “cloud” this is part of the htaccess for it in the root folder of the webserver:

RewriteEngine on RewriteCond %{HTTP_USER_AGENT} DavClnt RewriteRule ^$ /remote.php/webdav/ [L,R=302] RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}] RewriteRule ^\.well-known/carddav /cloud/remote.php/dav/ [R=301,L] RewriteRule ^\.well-known/caldav /cloud/remote.php/dav/ [R=301,L] RewriteRule ^\.well-known/webfinger /cloud/index.php/.well-known/webfinger [R=301,L] RewriteRule ^\.well-known/nodeinfo /cloud/index.php/.well-known/nodeinfo [R=301,L] RewriteRule ^remote/(.*) remote.php [QSA,L] RewriteRule ^(?:build|tests|config|lib|3rdparty|templates)/.* - [R=404,L] RewriteRule ^\.well-known/(?!acme-challenge|pki-validation) /index.php [QSA,L] RewriteRule ^(?:\.(?!well-known)|autotest|occ|issue|indie|db_|console).* - [R=404,L]

The same htaccess is in the subfolder /cloud but if I delete the htaccess in the root folder, nextcloud will say that nodeinfo and webfinger ist not properly configured.

How can I make nextcloud read the subfolder htaccess instead?

if I leave the htaccess in the root folder everything mostly works but I get a billion of these warnings in my log:

Exception: The requested uri(/favicon.ico) cannot be processed by the script ‘/cloud/index.php’)

Or I want to add a root folder .php it will not open it and display a nextcloud internal error message.

Say for example I create a phpinfo file in the root folder of the weberver, if I want to open it, it will display internal server error from nextcloud.

But if I delete the htaccess from root folder I can see phpinfo fine.

If you want to mess around with those kinds of directives for Nextcloud, you really should do so in your webserver configuration files instead of htaccess in the filesystem. If you change files in the webroot, you WILL break the Nextcloud upgrade functionality.

If you insist on putting in a “phpinfo” or other script, create a new tree OUTSIDE of the nextcloud webroot and refer to it using an alias in your nextcloud virtualhost in your webserver configuration, something like this; Alias "/phpinfo.php" "/var/www/otherfiles/phpinfo.php"

You’ll also need to define a Directory for that new webroot, something like this;

<Directory "/var/www/otherfiles">
   Order allow,deny
   Allow from all

Thanks Larry,

I registered a new domain there is a .cloud tld which was neat anyway. So I created a clean new environment for nextcloud where it can sit happily in the webroot / directory with no other php scripts and portals or CMS.

This way it seems to require much less customization and is less of a hassle.

Hi @Lawkss

In addition to the answer from Larry I just wanted to point out that a feature called VirtualHosts in Apache has been around for ages. :wink: No need to mess with different webroots in subfolders of the main domain. Each webroot can have it’s own configuration and run completley independent with or without .htaccess. There is also no technical need to use a separate domain name for each site, unless you want to for other reasons. You can just use a different subdomain for each virtual host. e.g cloud.yourdomain.tld, otherapp.yourdomain.tld etc.

Yes, however this assumes that you have access to DNS and that the use of alternative domains wouldn’t interfere with the objective, neither option was implied by OP. Seems that this was an option in this case, and that @Lawkss came to that conclusion on his own.

Yes you are right. I just wanted to point it out. I see a lot of people overcomplicating things here in the forums, and at other places. Sometimes there is no other way for them, beacuse of circumstances they can’t control, but in many cases there would be an easier way, that they not aware of.

But In this specific case the user created a clean new environment for Nextcloud, wich is the best solution anyways, also in terms of security…

…whatever new clean enviroment means… it could mean that he exactley did what I said, by creating a new VirtualHost in the admin panel of his webhosting company :wink:

1 Like

Pretty sure he created a new virtual host.

1 Like