url redirections not working for anonymous users I have set a redirect rule in EventSubscriber. So according to rule, when I hit example.com/my-page in browser, it should redirect to example.com/success or some external url also.

But issue is(for anonymous user):

On hitting first time this url "example.com/my-page", REDIRECT SUCCESS!! But on second time it does not redirect. It remains "example.com/my-page" only.

Now If I logged in, flush all cache, then again log out and check "example.com/my-page", it again works -- REDIRECT SUCCESS!! But again after redirecting first time when accessed the same, it stops redirecting.
This is probably because of the page cache for anonymous users. The cache is implemented as middleware and runs before any event subscriber, even if you set a  high priority.

If your site serves dynamically generated responses and redirects for every single request, then you don't need this cache and you can uninstall the module Internal Page Cache.

If you want to disable the page cache in code:

\Drupal::service('page_cache_kill_switch')-&gt;trigger();


This will deny any page caching on the current request.