Reputation: 31
How to be solved in a professional way without '/' in url redirecting to page with slash. Currently Shopware 6 has 404 error when is link without slash. I resolved it once in kernel event - response by checking uri path and add slash if uri didn't have it. I do not know if it was the right way.
This is my part of code which I tried to solve a problem:
if (str_ends_with($path, '/') && !$event->getResponse() instanceof StorefrontResponse) {
$response = new RedirectResponse($this->router->generate('frontend.home.page'), 301);
$event->setResponse($response);
return;
}
Upvotes: 1
Views: 535
Reputation: 501
KernelEvents::REQUEST
should fit. Because you might forward the request.
But, there is also a great plugin solving issues with slashes: https://store.shopware.com/en/kielc49617690410/trailing-slash-redirect.html
Upvotes: 2