Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
Expand Down Expand Up @@ -109,6 +110,16 @@ public function onRequestAddSiteFilter(RequestEvent $event) {
$path = $api_helper->getRequestedPath($request);
// Only prefix non-homepage and unrouted path.
if ($path !== '/') {
// If the path already has a site prefix, 301 redirect to the clean
// path so the FE uses canonical URLs without site prefixes.
if ($this->helper->hasSitePrefix($path)) {
$clean_path = preg_replace('#^/site-\d+/#', '/', $path);
$query = $request->query->all();
$query['path'] = $clean_path;
$redirect_url = $request->getBaseUrl() . $request->getPathInfo() . '?' . http_build_query($query);
$event->setResponse(new RedirectResponse($redirect_url, Response::HTTP_MOVED_PERMANENTLY));
return;
}
try {
$url = Url::fromUri('internal:' . $path);
if (!$url->isRouted() && !$this->helper->hasSitePrefix($path)) {
Expand Down
Loading