- Implemented configurable public URL rewriting.

What changed:
Added pretty URL helpers/default setting in 
[includes/db.php](/Users/tyemeclifford/Documents/GH/mediaplayer/includes/db.php).
Added root rewrite rules in 
[.htaccess](/Users/tyemeclifford/Documents/GH/mediaplayer/.htaccess):/v/<slug>
/all
/search/<query>

Added Admin → Settings “Public URL Style” toggle in 
[admin/settings.php](/Users/tyemeclifford/Documents/GH/mediaplayer/admin/settings.php), 
defaulting to pretty URLs.
Updated public/player/catalogue/embed/admin preview links to use the 
configured URL style.
Added redirects from legacy ?v= and ?q= URLs to pretty routes when 
rewriting is enabled.
Documented deployment and fallback behavior in 
[README.md](/Users/tyemeclifford/Documents/GH/mediaplayer/README.md).
This commit is contained in:
Ty Clifford
2026-06-24 13:16:55 -04:00
parent 0f262cab3f
commit 1abe5218ca
13 changed files with 187 additions and 30 deletions
+24 -5
View File
@@ -2,9 +2,28 @@
require_once __DIR__ . '/includes/db.php';
require_once __DIR__ . '/includes/layout.php';
$route_segments = public_route_segments();
$search = public_search_query_from_request();
if (url_rewrite_enabled()) {
$route_head = $route_segments[0] ?? '';
$target = null;
if (isset($_GET['q']) && $route_head !== 'search') {
$target = public_search_url($search);
} elseif (!isset($_GET['q']) && !in_array($route_head, ['all', 'search'], true)) {
$target = public_catalogue_url();
}
if ($target !== null) {
$redirect_page = max(1, (int)($_GET['page'] ?? 1));
if ($redirect_page > 1) $target = media_append_query($target, ['page' => (string)$redirect_page]);
header('Location: ' . $target, true, 302);
exit;
}
}
$per_page = (int)setting('catalogue_per_page', '10');
$page = max(1, (int)($_GET['page'] ?? 1));
$search = trim($_GET['q'] ?? '');
$paged = get_videos_paginated($page, $per_page, true, $search);
render_head('Videos — TyClifford.com', '
@@ -76,14 +95,14 @@ render_head('Videos — TyClifford.com', '
<?= $paged['total'] ?> <?= $search ? 'result' : 'video' ?><?= $paged['total'] != 1 ? 's' : '' ?>
</span>
</div>
<form class="public-search" method="get" action="catalogue.php" role="search">
<form class="public-search" method="get" action="<?= h(public_catalogue_url()) ?>" role="search">
<input class="form-input" type="search" name="q" value="<?= h($search) ?>" placeholder="Search public videos…">
<button class="btn btn-secondary btn-sm" type="submit">
<svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
Search
</button>
<?php if ($search): ?>
<a href="catalogue.php" class="btn btn-secondary btn-sm">Clear</a>
<a href="<?= h(public_catalogue_url()) ?>" class="btn btn-secondary btn-sm">Clear</a>
<?php endif; ?>
</form>
</div>
@@ -105,7 +124,7 @@ render_head('Videos — TyClifford.com', '
$vdur = (int)$v['duration'];
$created = substr($v['created_at'], 0, 10);
?>
<a class="cat-thumb" href="https://tyclifford.com/player/?v=<?= urlencode($vslug) ?>" title="<?= h($vtitle) ?>">
<a class="cat-thumb" href="<?= h(public_video_url($vslug)) ?>" title="<?= h($vtitle) ?>">
<div class="cat-thumb-img">
<?php if ($vthumb): ?>
<img src="<?= h(MEDIA_URL . $vthumb) ?>" alt="<?= h($vtitle) ?>" loading="lazy">
@@ -133,7 +152,7 @@ render_head('Videos — TyClifford.com', '
<?php if ($paged['total_pages'] > 1): ?>
<div class="cat-footer">
<span class="cat-count">page <?= $paged['page'] ?> of <?= $paged['total_pages'] ?></span>
<?php render_pagination($paged['page'], $paged['total_pages'], 'catalogue.php?' . ($search ? 'q=' . urlencode($search) . '&' : '') . 'page=%d'); ?>
<?php render_pagination($paged['page'], $paged['total_pages'], public_catalogue_page_url_pattern($search)); ?>
</div>
<?php endif; ?>
<?php endif; ?>