From 8c1380ec043911fd587a1e29b4a86dd1714977f3 Mon Sep 17 00:00:00 2001 From: Tykayn Date: Wed, 3 Sep 2025 16:00:45 +0200 Subject: [PATCH] redirect wiki pages to qualiwiki website --- WIKI_REDIRECT_DOCUMENTATION.md | 48 +++++++++++++++++ .../WikiRedirectSubscriber.php | 51 +++++++++++++++++++ 2 files changed, 99 insertions(+) create mode 100644 WIKI_REDIRECT_DOCUMENTATION.md create mode 100644 src/EventSubscriber/WikiRedirectSubscriber.php diff --git a/WIKI_REDIRECT_DOCUMENTATION.md b/WIKI_REDIRECT_DOCUMENTATION.md new file mode 100644 index 00000000..a2463074 --- /dev/null +++ b/WIKI_REDIRECT_DOCUMENTATION.md @@ -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. \ No newline at end of file diff --git a/src/EventSubscriber/WikiRedirectSubscriber.php b/src/EventSubscriber/WikiRedirectSubscriber.php new file mode 100644 index 00000000..41a9eeaa --- /dev/null +++ b/src/EventSubscriber/WikiRedirectSubscriber.php @@ -0,0 +1,51 @@ +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], + ]; + } +} \ No newline at end of file