owncloud-ansible/owncloud

Option for removing "index.php" from URL (aka rewritebase)

PVince81 opened this issue · 3 comments

Currently the URL of a provisioned instance always shows "index.php" in the URL.
There's an option to make it cleaner.

To make this work, I had to manually do the following on the provisioned instance:

  • edit config.php and add a key 'htaccess.RewriteBase' => '/'
  • run sudo -u www-data ./occ maintenance:update:htaccess

Here is how the end of the .htaccess file looks like after running the above occ command:

(...)
#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####

ErrorDocument 403 vagrant.owncloud.demo/core/templates/403.php
ErrorDocument 404 vagrant.owncloud.demo/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|json)$
  RewriteCond %{REQUEST_FILENAME} !core/img/favicon.ico$
  RewriteCond %{REQUEST_FILENAME} !/robots.txt
  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_FILENAME} !/ocm-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>

To detect the fact whether this is already correctly set, I guess that we could read the line "RewriteBase /" from the .htaccess file and see if it matches the one from config.php.

In general I guess that for such deployments we probably only support deploying on the server root, in which case we could always use "/" as default there.

Quick attempt at adding this in this PR: #15