From 0f2634749d741707ff15da620d464fe4423849f3 Mon Sep 17 00:00:00 2001 From: David Bailey Date: Thu, 13 Feb 2025 10:43:06 +0100 Subject: [PATCH] fix: :bug: fix handling of URLS (now uses config file prefix) --- www/.htaccess | 6 +++++- www/src/db_handler/post.php | 16 ++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/www/.htaccess b/www/.htaccess index 05ae513..1ceb07b 100644 --- a/www/.htaccess +++ b/www/.htaccess @@ -17,6 +17,10 @@ RewriteRule ^/?raw/(.*)$ raw/%{HTTP_HOST}/$1 [L,END] # RewriteCond %{HTTPS} !on # RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,END] +RewriteCond %{REQUEST_URI} !^/api/ +RewriteCond %{REQUEST_URI} /\w+$ +RewriteRule (.*) $1/ [R=301,L,END] + RewriteCond %{REQUEST_URI} !^/?(src/dbtest\.php|static|raw|robots\.txt).* RewriteRule (.*) src/router.php @@ -30,4 +34,4 @@ Options +Indexes Header set Cache-Control "max-age=60, public" - \ No newline at end of file + diff --git a/www/src/db_handler/post.php b/www/src/db_handler/post.php index 78935bb..1b0e5bd 100644 --- a/www/src/db_handler/post.php +++ b/www/src/db_handler/post.php @@ -96,9 +96,6 @@ class Post implements ArrayAccess { $data['basename'] ??= 'root'; } - $post_data['host'] ??= 'localhost:8081'; - - $data['url'] ??= 'http://' . $post_data['host'] . $post_data['path']; $data['basename'] ??= basename($data['path']); $data['title'] ??= basename($data['path']); @@ -107,6 +104,17 @@ class Post implements ArrayAccess { $data['type'] ??= self::deduce_type($post_data['path']); + if(!isset($data['url'])) { + $url = $site_defaults['uri_prefix'] . $post_data['path']; + // Adding a trailing slash for "non-filename" paths that + // need a trail to render properly + + if(!preg_match('/\.\w+$/', $url)) { + $url .= '/'; + } + $data['url'] = $url; + } + $data['icon'] ??= self::deduce_icon($data['type']); $data['template'] ??= self::deduce_template($data['type']); @@ -234,4 +242,4 @@ class Post implements ArrayAccess { } } -?> \ No newline at end of file +?>