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: 
Although Krukov's answer didn't solve my problem, it did lead me in the right direction. As stated in the [documentation](http://symfony.com/doc/current/cookbook/security/form_login.html#control-the-redirect-url-from-inside-the-form), you can add a hidden form input with a `name` attribute of `_target_path` to the log-in form, and it will attempt to redirect to the value of this input.

So in my LoginController::loginAction, I checked if there was a `redirect` query parameter present, and if so, sent it to the twig template and added the hidden input:

```
public function loginAction(Request $request)
{
    $page = $this->templating->render('AppBundle::login.html.twig', [
        'redirect' => $request->query->get('redirect') ?: null,
    ]);

    return new Response($page);
}

```

In the template:

```
<form action="{{ path('login_check') }}" method="post">
    {% if redirect %}
        <input name="_target_path" type="hidden" value="{{ redirect }}">
    {% endif %}

    <label for="username">Username</label>
    <input type="text" id="username" name="_username" value="{{ last_username }}" required>

    <label for="password">Password</label>
    <input type="password" id="password" name="_password" required>

    <input type="hidden" name="_csrf_token" value="{{ csrf_token('authenticate') }}">
    <button type="submit">Sign in</button>
</form>

```

(Extraneous code removed.)
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>