mirror of
https://github.com/nextcloud/server.git
synced 2026-05-19 16:39:59 -04:00
Merge pull request #24540 from owncloud/stable9-do-not-automatically-try-to-enable-index-php-less-urls
[Stable9] do not automatically try to enable index php less urls
This commit is contained in:
commit
56031fe155
7 changed files with 191 additions and 37 deletions
17
.htaccess
17
.htaccess
|
|
@ -59,23 +59,6 @@
|
|||
RewriteRule ^(build|tests|config|lib|3rdparty|templates)/.* - [R=404,L]
|
||||
RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*
|
||||
RewriteRule ^(\.|autotest|occ|issue|indie|db_|console).* - [R=404,L]
|
||||
|
||||
# Rewrite rules for `front_controller_active`
|
||||
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/.*
|
||||
</IfModule>
|
||||
<IfModule mod_mime.c>
|
||||
AddType image/svg+xml svg svgz
|
||||
|
|
|
|||
|
|
@ -361,6 +361,31 @@ $CONFIG = array(
|
|||
*/
|
||||
'overwrite.cli.url' => '',
|
||||
|
||||
/**
|
||||
* To have clean URLs without `/index.php` this parameter needs to be configured.
|
||||
*
|
||||
* This parameter will be written as "RewriteBase" on update and installation of
|
||||
* ownCloud to your `.htaccess` file. While this value is often simply the URL
|
||||
* path of the ownCloud installation it cannot be set automatically properly in
|
||||
* every scenario and needs thus some manual configuration.
|
||||
*
|
||||
* In a standard Apache setup this usually equals the folder that ownCloud is
|
||||
* accessible at. So if ownCloud is accessible via "https://mycloud.org/owncloud"
|
||||
* the correct value would most likely be "/owncloud". If ownCloud is running
|
||||
* under "https://mycloud.org/" then it would be "/".
|
||||
*
|
||||
* Note that above rule is not valid in every case, there are some rare setup
|
||||
* cases where this may not apply. However, to avoid any update problems this
|
||||
* configuration value is explicitly opt-in.
|
||||
*
|
||||
* After setting this value run `occ maintenance:update:htaccess` and when following
|
||||
* conditions are met ownCloud uses URLs without index.php in it:
|
||||
*
|
||||
* - `mod_rewrite` is installed
|
||||
* - `mod_env` is installed
|
||||
*/
|
||||
'htaccess.RewriteBase' => '/',
|
||||
|
||||
/**
|
||||
* The URL of your proxy server, for example ``proxy.example.com:8081``.
|
||||
*/
|
||||
|
|
|
|||
44
core/command/maintenance/updatehtaccess.php
Normal file
44
core/command/maintenance/updatehtaccess.php
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Lukas Reschke <lukas@owncloud.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
namespace OC\Core\Command\Maintenance;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use OC\Setup;
|
||||
use OCP\IConfig;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class UpdateHtaccess extends Command {
|
||||
|
||||
protected function configure() {
|
||||
$this
|
||||
->setName('maintenance:update:htaccess')
|
||||
->setDescription('Updates the .htaccess file');
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output) {
|
||||
\OC\Setup::updateHtaccess();
|
||||
$output->writeln('.htaccess has been updated');
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -113,6 +113,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
|
|||
$application->add(new OC\Core\Command\Maintenance\Mode(\OC::$server->getConfig()));
|
||||
$application->add(new OC\Core\Command\Maintenance\Repair(new \OC\Repair(\OC\Repair::getRepairSteps()), \OC::$server->getConfig()));
|
||||
$application->add(new OC\Core\Command\Maintenance\SingleUser(\OC::$server->getConfig()));
|
||||
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
|
||||
|
||||
$application->add(new OC\Core\Command\Upgrade(
|
||||
\OC::$server->getConfig(),
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ use OC\Hooks\Emitter;
|
|||
use OC\Repair\AssetCache;
|
||||
use OC\Repair\CleanTags;
|
||||
use OC\Repair\Collation;
|
||||
use OC\Repair\CopyRewriteBaseToConfig;
|
||||
use OC\Repair\DropOldJobs;
|
||||
use OC\Repair\OldGroupMembershipShares;
|
||||
use OC\Repair\RemoveGetETagEntries;
|
||||
|
|
@ -142,6 +143,7 @@ class Repair extends BasicEmitter {
|
|||
new Collation(\OC::$server->getConfig(), $connection),
|
||||
new SqliteAutoincrement($connection),
|
||||
new SearchLuceneTables(),
|
||||
new CopyRewriteBaseToConfig(\OC::$server->getConfig()),
|
||||
];
|
||||
|
||||
//There is no need to delete all previews on every single update
|
||||
|
|
|
|||
89
lib/private/repair/copyrewritebasetoconfig.php
Normal file
89
lib/private/repair/copyrewritebasetoconfig.php
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
<?php
|
||||
/**
|
||||
* @author Lukas Reschke <lukas@owncloud.com>
|
||||
*
|
||||
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
||||
* @license AGPL-3.0
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License, version 3,
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OC\Repair;
|
||||
|
||||
use OC\Hooks\BasicEmitter;
|
||||
use OC\RepairStep;
|
||||
use OCP\IConfig;
|
||||
|
||||
/**
|
||||
* Class CopyRewriteBaseToConfig
|
||||
*
|
||||
* @package OC\Repair
|
||||
*/
|
||||
class CopyRewriteBaseToConfig extends BasicEmitter implements RepairStep {
|
||||
/** @var IConfig */
|
||||
private $config;
|
||||
|
||||
/**
|
||||
* @param IConfig $config
|
||||
*/
|
||||
public function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getName() {
|
||||
return 'Copy the rewrite base to the config file';
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function run() {
|
||||
$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
|
||||
|
||||
$versionsToApplyFrom = [
|
||||
'9.0.0.19',
|
||||
'9.0.1.3',
|
||||
'9.0.2.2',
|
||||
];
|
||||
|
||||
if(in_array($ocVersionFromBeforeUpdate, $versionsToApplyFrom, true)) {
|
||||
// For CLI read the value from overwrite.cli.url
|
||||
if(\OC::$CLI) {
|
||||
$webRoot = $this->config->getSystemValue('overwrite.cli.url', '');
|
||||
if($webRoot === '') {
|
||||
return;
|
||||
}
|
||||
$webRoot = parse_url($webRoot, PHP_URL_PATH);
|
||||
$webRoot = rtrim($webRoot, '/');
|
||||
} else {
|
||||
$webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
|
||||
}
|
||||
|
||||
// ownCloud may be configured to live at the root folder without a
|
||||
// trailing slash being specified. In this case manually set the
|
||||
// rewrite base to `/`
|
||||
$rewriteBase = $webRoot;
|
||||
if($webRoot === '') {
|
||||
$rewriteBase = '/';
|
||||
}
|
||||
|
||||
$this->config->setSystemValue('htaccess.RewriteBase', $rewriteBase);
|
||||
\OC\Setup::updateHtaccess();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -420,37 +420,47 @@ class Setup {
|
|||
|
||||
$htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
|
||||
$content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n";
|
||||
if(strpos($htaccessContent, $content) === false) {
|
||||
//custom 403 error page
|
||||
$content.= "\nErrorDocument 403 ".$webRoot."/core/templates/403.php";
|
||||
$htaccessContent = explode($content, $htaccessContent, 2)[0];
|
||||
|
||||
//custom 404 error page
|
||||
$content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php";
|
||||
//custom 403 error page
|
||||
$content.= "\nErrorDocument 403 ".$webRoot."/core/templates/403.php";
|
||||
|
||||
// ownCloud may be configured to live at the root folder without a
|
||||
// trailing slash being specified. In this case manually set the
|
||||
// rewrite base to `/`
|
||||
$rewriteBase = $webRoot;
|
||||
if($webRoot === '') {
|
||||
$rewriteBase = '/';
|
||||
}
|
||||
//custom 404 error page
|
||||
$content.= "\nErrorDocument 404 ".$webRoot."/core/templates/404.php";
|
||||
|
||||
// Add rewrite base
|
||||
// Add rewrite rules if the RewriteBase is configured
|
||||
$rewriteBase = $config->getSystemValue('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} !/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} !/updater/";
|
||||
$content .= "\n RewriteCond %{REQUEST_FILENAME} !/ocs-provider/";
|
||||
$content .= "\n RewriteCond %{REQUEST_URI} !^/.well-known/acme-challenge/.*";
|
||||
$content .= "\n RewriteRule . index.php [PT,E=PATH_INFO:$1]";
|
||||
$content .= "\n RewriteBase ".$rewriteBase;
|
||||
$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>";
|
||||
$content .= "\n </IfModule>";
|
||||
$content .= "\n</IfModule>";
|
||||
}
|
||||
|
||||
if ($content !== '') {
|
||||
//suppress errors in case we don't have permissions for it
|
||||
@file_put_contents($setupHelper->pathToHtaccess(), $content . "\n", FILE_APPEND);
|
||||
}
|
||||
if ($content !== '') {
|
||||
//suppress errors in case we don't have permissions for it
|
||||
@file_put_contents($setupHelper->pathToHtaccess(), $htaccessContent.$content . "\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue