redirect wiki pages to qualiwiki website

This commit is contained in:
Tykayn 2025-09-03 16:00:45 +02:00 committed by tykayn
parent d68f738a4b
commit 8c1380ec04
2 changed files with 99 additions and 0 deletions

View file

@ -0,0 +1,48 @@
# Wiki Redirection Implementation
## Overview
This document explains the implementation of the redirection from `/wiki` routes to `https://qualiwiki.cipherbliss.com/wiki`.
## Implementation Details
The redirection is implemented using a Symfony Event Subscriber that intercepts all requests to paths starting with `/wiki` before they reach the routing system.
### Files Created
- `src/EventSubscriber/WikiRedirectSubscriber.php`: Event subscriber that handles the redirection
### How It Works
1. The `WikiRedirectSubscriber` subscribes to the `kernel.request` event with a high priority (256)
2. When a request is received, the subscriber checks if the path starts with `/wiki`
3. If it does, it extracts the part after `/wiki` and constructs a redirect URL by appending this part to `https://qualiwiki.cipherbliss.com/wiki`
4. It creates a 301 (permanent) redirect response and sets it on the event
5. This short-circuits the request handling process, preventing the request from reaching the routing system
### Example Redirects
- `/wiki``https://qualiwiki.cipherbliss.com/wiki`
- `/wiki/``https://qualiwiki.cipherbliss.com/wiki`
- `/wiki/page1``https://qualiwiki.cipherbliss.com/wiki/page1`
- `/wiki/page1/subpage``https://qualiwiki.cipherbliss.com/wiki/page1/subpage`
### Technical Considerations
- The subscriber uses a high priority (256) to ensure it runs before the router processes the request
- It only processes main requests, not sub-requests
- It uses a 301 (permanent) redirect status code, which is appropriate for this type of redirection
- The implementation follows Symfony best practices for event subscribers
- The subscriber is automatically registered thanks to Symfony's auto-configuration feature
## Testing
To test the redirection:
1. Access any path starting with `/wiki` in the application
2. Verify that you are redirected to the corresponding path on `https://qualiwiki.cipherbliss.com/wiki`
3. Check that the redirect is a 301 (permanent) redirect
## Maintenance
If the target URL needs to be changed in the future, update the `REDIRECT_BASE_URL` constant in the `WikiRedirectSubscriber` class.

View file

@ -0,0 +1,51 @@
<?php
namespace App\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpFoundation\RedirectResponse;
class WikiRedirectSubscriber implements EventSubscriberInterface
{
private const WIKI_PATH_PREFIX = '/wiki';
private const REDIRECT_BASE_URL = 'https://qualiwiki.cipherbliss.com/wiki';
public function onKernelRequest(RequestEvent $event): void
{
// Don't do anything if it's not the master request
if (!$event->isMainRequest()) {
return;
}
$request = $event->getRequest();
$path = $request->getPathInfo();
// Check if the path starts with /wiki
if (str_starts_with($path, self::WIKI_PATH_PREFIX)) {
// Extract the part after /wiki
$subPath = substr($path, strlen(self::WIKI_PATH_PREFIX));
// If subPath is empty or just a slash, redirect to the base URL
if (empty($subPath) || $subPath === '/') {
$redirectUrl = self::REDIRECT_BASE_URL;
} else {
// Otherwise, append the subPath to the redirect URL
$redirectUrl = self::REDIRECT_BASE_URL . $subPath;
}
// Create a redirect response
$response = new RedirectResponse($redirectUrl, 301); // 301 is permanent redirect
$event->setResponse($response);
}
}
public static function getSubscribedEvents(): array
{
// Use a high priority to intercept the request before the router
return [
KernelEvents::REQUEST => ['onKernelRequest', 256],
];
}
}