Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretty URLs: its complicated #11673

Closed
mcnesium opened this issue Oct 8, 2018 · 7 comments
Closed

Pretty URLs: its complicated #11673

mcnesium opened this issue Oct 8, 2018 · 7 comments

Comments

@mcnesium
Copy link

mcnesium commented Oct 8, 2018

I run two instances of Nextcloud 14.0.1. One is run inside Docker using nextcloud:latest image, the other one is run on Uberspace 6, installed with the web-installer.

Admittedly I did not pay much attention until recently for this issue, so I don't know if it has always been this way, but since upgrade to v14 both instances had …/index.php/… in their URLs. I did add a trailing slash to overwrite.cli.url, then the Docker instance had pretty URLs, the Uberspace one did not. Questions rose…

Then I found that the Docker one has this part at the very bottom 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|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|pki-validation)/.*
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>

which the Uberspace one does not. I copied this to the Uberspace .htaccess but it did not help.

Now here comes the interesting part:

I ran php occ maintenance:update:htaccess on the Uberspace (non-Docker) instance, and this removed the stuff from .htaccess. Then I manually removed it from .htaccess on the Docker instance, ran php occ maintenance:update:htaccess and found all the stuff being back in the file. 0o

So, what is this maintenance:update:htaccess actually doing? And why is it doing different stuff on different instances? And why do pretty URLs work on one and not on the other instances?

Sidenote: this is not the only incidence of different behavior of those two instances

@nextcloud-bot
Copy link
Member

GitMate.io thinks possibly related issues are #9182 (Just a question // Feature request // Pretty Share URL), #10471 (Improve URL detection), #7781 (htacces & pretty urls), and #6889 ([11.0.3 -> 12.0.3] Upgrade emptied .htaccess).

@kesselb
Copy link
Contributor

kesselb commented Oct 8, 2018

// Add rewrite rules if the RewriteBase is configured
$rewriteBase = $config->getValue('htaccess.RewriteBase', '');
if($rewriteBase !== '') {
$content .= "\n<IfModule mod_rewrite.c>";
$content .= "\n Options -MultiViews";
$content .= "\n RewriteRule ^core/js/oc.js$ index.php [PT,E=PATH_INFO:$1]";
$content .= "\n RewriteRule ^core/preview.png$ index.php [PT,E=PATH_INFO:$1]";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !\\.(css|js|svg|gif|png|html|ttf|woff|ico|jpg|jpeg)$";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !core/img/manifest.json$";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/remote.php";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/public.php";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/cron.php";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/core/ajax/update.php";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/status.php";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v1.php";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs/v2.php";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/robots.txt";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/updater/";
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs-provider/";
$content .= "\n RewriteCond %{REQUEST_URI} !^/\\.well-known/(acme-challenge|pki-validation)/.*";
$content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:$1]";
$content .= "\n RewriteBase " . $rewriteBase;
$content .= "\n <IfModule mod_env.c>";
$content .= "\n SetEnv front_controller_active true";
$content .= "\n <IfModule mod_dir.c>";
$content .= "\n DirectorySlash off";
$content .= "\n </IfModule>";
$content .= "\n </IfModule>";
$content .= "\n</IfModule>";
}

When htaccess.RewriteBase is not empty than these rules are written to htaccess. Is this value configured for your uberspace instance?

@mcnesium
Copy link
Author

mcnesium commented Oct 8, 2018

yes, both instances have 'htaccess.RewriteBase' => '/', in their config.php

@kesselb
Copy link
Contributor

kesselb commented Oct 8, 2018

When you execute php occ maintenance:update:htaccess you should either see .htaccess has been updated or Error updating .htaccess file, not enough permissions or "overwrite.cli.url" set to an invalid URL?

Could you execute php occ maintenance:update:htaccess; echo $?? The last part should echo the return code (0 or 1).

@mcnesium
Copy link
Author

mcnesium commented Oct 8, 2018

Sorry, I was not specific enough. The Uberspace instance did not have htaccess.RewriteBase in the config. But after I added that, it did not change the …/index.php/… being in the URL. I did not recheck what happened to the maintenance:update:htaccess command. Now I rechecked that, and it now has the IfModule mod_rewrite.c part inside as well. Still, no pretty URLs :(

@kesselb
Copy link
Contributor

kesselb commented Oct 8, 2018

'htaccess.IgnoreFrontController' => false

You need to set the above when mod_env is not available (https://docs.nextcloud.com/server/13/admin_manual/configuration_server/config_sample_php_parameters.html). Looks like mod_env is not available for uberspace (https://wiki.uberspace.de/webserver:suexec#kompatibilitaet_mit_mod_env).

Please keep in mind that github is for software issues and https://help.nextcloud.com/ for configuration issues.

@kesselb kesselb closed this as completed Oct 8, 2018
@mcnesium
Copy link
Author

mcnesium commented Oct 8, 2018

I know, but here people actually read and respond to stuff. My help post is stray for two weeks now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants