Question: In a Symfony2/3 project, if an anonymous user is on a semi-protected page (where portions of the page are only displayed to signed-in users), and they click a link that says, 'Sign in to view more details', how can I redirect them to the page they were on after signing in?

This is different from when they click a link to a fully-protected page, as the Symfony security framework automatically handles the redirect.

Is there something like this built in, or will I have to add it? I'm thinking of adding a query parameter to the end of the link to the sign-in page called `redirect`. For example, in Twig,

```
<a href="{{ path('login_route', {'redirect': '/profile/123'}) }}">
    Sign in to view more details
</a>

```

which would render as

```
<a href="/user/login?redirect=/profile/123">Sign in to view more details</a>

```

If this functionality doesn't already exist, I know I'll have to add something to the `loginCheckAction` in the `LoginController` (which isn't currently being used because the route is handled by the security system), but I'm not sure how.

[Here](http://symfony.com/doc/current/reference/configuration/security.html) is the Security Bundle configuration page which lists all the options, but I can't find anything in there about what I'm looking for.

Answer: 
You should add a listener to login success event of your security bundle, or, alternatively extend the bundle and implement your own login action inside it
([documentation](http://symfony.com/doc/current/cookbook/bundles/inheritance.html))
You can simply use "default\_target\_path" in app/config/security.yml
Look these docs: <http://symfony.com/doc/current/cookbook/security/form_login.html>