Files
deepseek beaf0e1f37 Toolvana: production-ready media tools platform (CodeIgniter 4)
- 134-tool registry with programmatic SEO (unique titles/H1/descriptions,
  JSON-LD graphs, sitemap index, canonical 301 enforcement via required filter)
- DB-backed job queue (SKIP LOCKED) with drivers: Ffmpeg, Images (GD),
  Pdf (qpdf/gs/poppler), Youtube (thumbnails), Qr (server-side PNG)
- Security: SSRF guard, MIME validation, rate limits, API-key auth,
  bcrypt admin login, security headers
- Admin panel: dashboard, tools/categories/guides CRUD, SEO audit,
  analytics, job inspector with retry, system health, feature flags
- Docker deployment (nginx + web/api FPM pools + scalable workers),
  PHPUnit suite (19 tests / 1139 assertions), PWA manifest + service worker
2026-08-23 07:10:30 +00:00

72 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Filters;
use CodeIgniter\Filters\FilterInterface;
use CodeIgniter\HTTP\RequestInterface;
use CodeIgniter\HTTP\ResponseInterface;
/**
* Canonical URL enforcement for SEO: any request that differs from the
* canonical lowercase, no-trailing-slash form is 301-redirected before
* routing. Prevents duplicate-content across case variants and slashes.
*/
final class SeoCanonical implements FilterInterface
{
public function before(RequestInterface $request, $arguments = null)
{
if (! $request instanceof \CodeIgniter\HTTP\IncomingRequest) {
return null;
}
// Only GET/HEAD matter for indexing.
if (! in_array(strtolower($request->getMethod()), ['get', 'head'], true)) {
return null;
}
$path = trim(uri_string());
if ($path === '') {
$path = trim($request->getUri()->getPath(), '/');
}
// Skip files that legitimately end with a slash-like pattern or assets
if ($path === '' || str_contains($path, '.')) {
return null;
}
$needsRedirect = false;
// trailing slash
if (str_ends_with($path, '/')) {
$path = rtrim($path, '/');
$needsRedirect = true;
}
// uppercase / mixed case
if ($path !== mb_strtolower($path)) {
$path = mb_strtolower($path);
$needsRedirect = true;
}
// multiple consecutive slashes
if (str_contains($path, '//')) {
$path = preg_replace('#/+#', '/', $path);
$needsRedirect = true;
}
if ($needsRedirect) {
return redirect()->to($path !== '' ? '/' . ltrim((string) $path, '/') : '/')
->setStatusCode(301);
}
return null;
}
public function after(RequestInterface $request, ResponseInterface $response, $arguments = null)
{
return null;
}
}