Support using Shaarli without URL rewriting

- Shaarli can be fully used by prefixing any URL with /index.php/
   - {$base_path} used in templates already works with this configuration
   - Assets path (outside of theme's assets) must be prefixed with {$root_url}/
   - Documentation section in « Server configuration »

Fixes #1590
This commit is contained in:
ArthurHoaro 2020-10-16 12:47:11 +02:00
parent ec45749187
commit 7f5250421b
10 changed files with 31 additions and 11 deletions

View file

@ -174,10 +174,12 @@ class PageBuilder
}
}
$rootPath = preg_replace('#/index\.php$#', '', $basePath);
$this->assign('base_path', $basePath);
$this->assign('root_path', $rootPath);
$this->assign(
'asset_path',
$basePath . '/' .
$rootPath . '/' .
rtrim($this->conf->get('resource.raintpl_tpl', 'tpl'), '/') . '/' .
$this->conf->get('resource.theme', 'default')
);

View file

@ -362,7 +362,23 @@ sudo systemctl reload nginx
If Shaarli is hosted on a server behind a [reverse proxy](https://en.wikipedia.org/wiki/Reverse_proxy) (i.e. there is a proxy server between clients and the web server hosting Shaarli), configure it accordingly. See [Reverse proxy](Reverse-proxy.md) configuration.
## Using Shaarli without URL rewriting
By default, Shaarli uses Slim framework's URL, which requires
URL rewriting.
If you can't use URL rewriting for any reason (not supported by
your web server, shared hosting, etc.), you *can* use Shaarli
without URL rewriting.
You just need to prefix your URL by `/index.php/`.
Example: instead of accessing `https://shaarli.mydomain.org/`,
use `https://shaarli.mydomain.org/index.php/`.
**Recommended:**
* after installation, in the configuration page, set your header link to `/index.php/`.
* in you `config.json.php` set `general.root_url` to
`https://shaarli.mydomain.org/index.php/`.
## Allow import of large browser bookmarks export

View file

@ -17,7 +17,8 @@ use Shaarli\Plugin\PluginManager;
function hook_archiveorg_render_linklist($data)
{
$archive_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/archiveorg/archiveorg.html');
$path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
$rootPath = preg_replace('#/index\.php$#', '', $data['_BASE_PATH_'] ?? '');
$path = $rootPath . '/' . PluginManager::$PLUGINS_PATH;
foreach ($data['links'] as &$value) {
$isNote = startsWith($value['real_url'], '/shaare/');

View file

@ -19,7 +19,8 @@ function hook_qrcode_render_linklist($data)
{
$qrcode_html = file_get_contents(PluginManager::$PLUGINS_PATH . '/qrcode/qrcode.html');
$path = ($data['_BASE_PATH_'] ?? '') . '/' . PluginManager::$PLUGINS_PATH;
$rootPath = preg_replace('#/index\.php$#', '', $data['_BASE_PATH_'] ?? '');
$path = $rootPath . '/' . PluginManager::$PLUGINS_PATH;
foreach ($data['links'] as &$value) {
$qrcode = sprintf(
$qrcode_html,

View file

@ -76,7 +76,7 @@
</div>
{if="$thumbnails_enabled && !empty($link.thumbnail)"}
<div class="daily-entry-thumbnail">
<img data-src="{$link.thumbnail}#" class="b-lazy"
<img data-src="{$root_path}/{$link.thumbnail}#" class="b-lazy"
src=""
alt="thumbnail" width="{$thumbnails_width}" height="{$thumbnails_height}" />
</div>

View file

@ -12,10 +12,10 @@
<link type="text/css" rel="stylesheet" href="{$asset_path}/css/markdown.min.css?v={$version_hash}#" />
{/if}
{loop="$plugins_includes.css_files"}
<link type="text/css" rel="stylesheet" href="{$base_path}/{$value}?v={$version_hash}#"/>
<link type="text/css" rel="stylesheet" href="{$root_path}/{$value}?v={$version_hash}#"/>
{/loop}
{if="is_file('data/user.css')"}
<link type="text/css" rel="stylesheet" href="{$base_path}/data/user.css#" />
<link type="text/css" rel="stylesheet" href="{$root_path}/data/user.css#" />
{/if}
<link rel="search" type="application/opensearchdescription+xml" href="{$base_path}/open-search#"
title="Shaarli search - {$shaarlititle}" />

View file

@ -140,7 +140,7 @@
<div class="thumbnail">
{ignore}RainTPL hack: put the 2 src on two different line to avoid path replace bug{/ignore}
<a href="{$value.real_url}" aria-hidden="true" tabindex="-1">
<img data-src="{$base_path}/{$value.thumbnail}#" class="b-lazy"
<img data-src="{$root_path}/{$value.thumbnail}#" class="b-lazy"
src=""
alt="" width="{$thumbnails_width}" height="{$thumbnails_height}" />
</a>

View file

@ -10,7 +10,7 @@
{/if}
&middot;
{'The personal, minimalist, super-fast, database free, bookmarking service'|t} {'by the Shaarli community'|t} &middot;
<a href="{$base_path}/doc/html/index.html" rel="nofollow">{'Documentation'|t}</a>
<a href="{$root_path}/doc/html/index.html" rel="nofollow">{'Documentation'|t}</a>
{loop="$plugins_footer.text"}
{$value}
{/loop}
@ -25,7 +25,7 @@
{/loop}
{loop="$plugins_footer.js_files"}
<script src="{$base_path}/{$value}#"></script>
<script src="{$root_path}/{$value}#"></script>
{/loop}
<div id="js-translations" class="hidden">

View file

@ -31,7 +31,7 @@
{loop="$linksToDisplay"}
<div class="picwall-pictureframe" role="listitem">
{ignore}RainTPL hack: put the 2 src on two different line to avoid path replace bug{/ignore}
<img data-src="{$value.thumbnail}#" class="b-lazy"
<img data-src="{$root_path}/{$value.thumbnail}#" class="b-lazy"
src=""
alt="" width="{$thumbnails_width}" height="{$thumbnails_height}" />
<a href="{$value.real_url}"><span class="info">{$value.title}</span></a>

View file

@ -117,7 +117,7 @@
<div class="center more">
{"More plugins available"|t}
<a href="doc/html/Community-&-Related-software/#third-party-plugins">{"in the documentation"|t}</a>.
<a href="{$root_path}/doc/html/Community-&-Related-software/#third-party-plugins">{"in the documentation"|t}</a>.
</div>
<div class="center">
<input type="submit" value="{'Save'|t}" name="save">