implement full support for relative path
{{toc numerate=1}}
===Objectives===
1. add support for relative path
2. option to set only absolute path, enforce canonical URL
3. option to auto set relative path/absolute URL
* always adjusts to current environment
* to run under multiple domains
Patches
1. ((commit:a7fb41de84d9310061c3ca5d7a672c902a6f8b31 added option to switch between absolute and relative links))
2. ((commit:4363763ec9f01f6226a9782f6eda94bc08701cc7 set canonical context for feeds))
impediments
* parse_url & unicode
absolute path must ensured for
1. cookiesURL
1. redirect
1. canonical
1. sitemap
1. XML feeds
1. email content
#|
*| Types | Example |*
|| absolute URL | ##~https://example.com/folder/image.png## ||
|| protocol-relative URL | ##//example.com/folder/image.png## ||
|| root-relative URL | ##/folder/image.png## ||
|| base-relative URL | ##folder/image.png## ||
|#
===Config===
If ##canonical## is not enforced, ##base_path## is applied where possible, all other cases use always ##base_url##.
* base_url (absolute)
* base_path (relative)
* base_path (canonical ? base_url : base_path)
%%(php)
<?php
'base_url' => ($_SERVER['SERVER_PORT'] == 443
? 'https'
: 'http'
) . '://' .
$_SERVER['SERVER_NAME'] .
(!in_array($_SERVER['SERVER_PORT'], [80, 443])
? ':' . $_SERVER['SERVER_PORT']
: ''
) .
(($path = preg_replace('/\/\//', '\/', trim(strtr(dirname($_SERVER['SCRIPT_NAME']), '\\', '/'), '/')))
? '/' . $path
: ''
) . '/' ,
%%
====Get base URL====
%%(php)
<?php
// returns the full absolute or relative URL to the directory where WackoWiki is installed
function get_base_url($absolute = null)
{
$base_url = ($_SERVER['SERVER_PORT'] == 443
? 'https'
: 'http'
) . '://' .
$_SERVER['SERVER_NAME'] .
(!in_array($_SERVER['SERVER_PORT'], [80, 443])
? ':' . $_SERVER['SERVER_PORT']
: ''
);
$base_path = (($path = preg_replace('/\/\//', '\/', trim(strtr(dirname($_SERVER['SCRIPT_NAME']), '\\', '/'), '/')))
? '/' . $path
: ''
) . '/';
return ($absolute ? $base_url : '') . $base_path;
}
%%
===Relative URLs===
<a href="##/wiki/##">
%% 'base_url' => '/wiki/', %%
===Absolute URLs===
<a href="##~https://example.com/wiki/##">
%% 'base_url' => 'http://example.com/wiki/', %%
%%
$base_url = 'http[s]://example.com/wiki/';
$base_path = '/wiki/';
%%
===Canonical context===
It sets canonical context for feeds, this solves three issues:
* ##format($page['body_r'], 'post_wacko')## -> renders content with canonical links
* ##href()## -> sets link absolute
* ##link()## -> sets path for global files absolute
===Resources===
* ((https://tools.ietf.org/html/rfc2396 RFC 2396 - Uniform Resource Identifiers (URI): Generic Syntax))
* ((https://stackoverflow.com/questions/2005079/absolute-vs-relative-urls Absolute vs relative URLs))