Skip to content
Snippets Groups Projects
Commit 0de90cfc authored by Morris Jobke's avatar Morris Jobke
Browse files

Fix 403 and 404 redirect


* Nextcloud is not properly loaded in the standalone version (especially the theming)
* it is already not listed anymore in the Nginx config (see nextcloud/documentation#392)
* the index.php-free version doesn't support this

Signed-off-by: default avatarMorris Jobke <hey@morrisjobke.de>
parent 174cd4f4
No related branches found
No related tags found
No related merge requests found
<?php <?php
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
if(!isset($_)) {//also provide standalone error page if(!isset($_)) {//standalone page is not supported anymore - redirect to /
require_once '../../lib/base.php'; require_once '../../lib/base.php';
$tmpl = new OC_Template( '', '403', 'guest' ); $urlGenerator = \OC::$server->getURLGenerator();
$tmpl->printPage(); header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
exit; exit;
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
......
...@@ -3,11 +3,11 @@ ...@@ -3,11 +3,11 @@
/** @var $l \OCP\IL10N */ /** @var $l \OCP\IL10N */
/** @var $theme OCP\Defaults */ /** @var $theme OCP\Defaults */
// @codeCoverageIgnoreStart // @codeCoverageIgnoreStart
if(!isset($_)) {//also provide standalone error page if(!isset($_)) {//standalone page is not supported anymore - redirect to /
require_once '../../lib/base.php'; require_once '../../lib/base.php';
$tmpl = new OC_Template( '', '404', 'guest' ); $urlGenerator = \OC::$server->getURLGenerator();
$tmpl->printPage(); header('Location: ' . $urlGenerator->getAbsoluteURL('/'));
exit; exit;
} }
// @codeCoverageIgnoreEnd // @codeCoverageIgnoreEnd
......
...@@ -449,10 +449,10 @@ class Setup { ...@@ -449,10 +449,10 @@ class Setup {
$htaccessContent = explode($content, $htaccessContent, 2)[0]; $htaccessContent = explode($content, $htaccessContent, 2)[0];
//custom 403 error page //custom 403 error page
$content.= "\nErrorDocument 403 ".$webRoot."/core/templates/403.php"; $content.= "\nErrorDocument 403 ".$webRoot."/";
//custom 404 error page //custom 404 error page
$content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php"; $content.= "\nErrorDocument 404 ".$webRoot."/";
// Add rewrite rules if the RewriteBase is configured // Add rewrite rules if the RewriteBase is configured
$rewriteBase = $config->getValue('htaccess.RewriteBase', ''); $rewriteBase = $config->getValue('htaccess.RewriteBase', '');
......
<?php
namespace Tests\Core\Templates;
class TemplatesTest extends \Test\TestCase {
public function test403() {
$template = \OC::$SERVERROOT . '/core/templates/403.php';
$expectedHtml = "<ul><li class='error'>\n\t\tAccess forbidden<br><p class='hint'></p></li></ul>";
$this->assertTemplate($expectedHtml, $template);
}
public function test404() {
$template = \OC::$SERVERROOT . '/core/templates/404.php';
$href = \OC::$server->getURLGenerator()->linkTo('', 'index.php');
$expectedHtml = "<ul><li class='error'>\n\t\t\tFile not found<br><p class='hint'>The specified document has not been found on the server.</p>\n<p class='hint'><a href='$href'>You can click here to return to Nextcloud.</a></p>\n\t\t</li></ul>";
$this->assertTemplate($expectedHtml, $template);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment