# How to redirect to home page from a subscriber file?

**URL:** <https://forum.shopware.com/t/how-to-redirect-to-home-page-from-a-subscriber-file/65104>\
**Category:** Programming (EN)\
**Created:** [2. März 2020 um 07:02 UTC](https://forum.shopware.com/t/how-to-redirect-to-home-page-from-a-subscriber-file/65104 "2020-03-02T07:02:06Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![abinjohnedamana](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.shopware.com/abinjohnedamana/32/17378_2.png) [@abinjohnedamana](https://forum.shopware.com/u/abinjohnedamana)\
**Post date:** [9. März 2020 um 04:36 UTC](https://forum.shopware.com/t/how-to-redirect-to-home-page-from-a-subscriber-file/65104/2 "2020-03-09T04:36:46Z")

</div>

If you want to redirect in Shopware way you have to use an event like “RequestEvent”.

```
    use Symfony\Component\HttpFoundation\RedirectResponse;
    use Symfony\Component\HttpKernel\Event\RequestEvent;
    use Symfony\Component\HttpKernel\KernelEvents;

    public static function getSubscribedEvents(): array
    {
        return [
            KernelEvents::REQUEST => 'onCmsPageLoaded'
        ];
    }

    public function onCmsPageLoaded(RequestEvent $event)
    {
        $request = $event->getRequest();

        $attributes = $request->attributes;

        $route = $attributes->get('_route');

        if($route == 'frontend.cms.page')
        {
	    $response = new RedirectResponse($this->router->generate('frontend.home.page'), 301);

	    $event->setResponse($response);

	    return;
        }
    }

```

&nbsp;

---

_[View the full topic](https://forum.shopware.com/t/how-to-redirect-to-home-page-from-a-subscriber-file/65104)._
