title: Symfony2: Redirect to previous page after login
body: <p>I want to do this:</p>
  
  <p>User try to access to a private page (he needs to be logged). When he try to access, he can't access becaouse previously he has to write his credentials. He write his passowrd and log in in the system. I want to the user will be automatically redirected to the page he tried to access.</p>
  
  <p>I put in security.yml</p>
  
  <pre><code>use_referer: true
  </code></pre>
  
  <p>And in my first controller I put:</p>
  
  <pre><code>$this-&gt;getRequest()-&gt;headers-&gt;get('referer');
  </code></pre>
  
  <p>And I always get the address of the login (.../login.php). Instead of this, I need to obtain for example (.../downloads/test.txt) </p>
  
  <p>I also tried with:</p>
  
  <pre><code>$request-&gt;getSession()-&gt;get('_security.account.target_path');
  </code></pre>
  
  <p>But I get null.</p>
  
  <p>How can I do this?</p>
  
  <p>Thanks in advance!</p>
  
  <p>--- Edit with security.yml ---</p>
  
  <pre><code>firewalls:
      frontend:
          pattern:     ^/*
          anonymous:   ~
          simple-form:  
              authenticator: my_authenticator
              check_path: login_check
              login_path: login
              use_referer: true
              failure_path: login_error
          logout:
              path:    logout
              target:  /
              success_handler: my_authenticator
          remember_me:
              key:       mykey
              lifetime:  31536000
  
          switch_user: { role: ROLE_ADMIN, parameter: _login_as }
  
  access_control:
      - { path: ^/web/login.php, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
      - { path: ^/web/login_error.php, roles: IS_AUTHENTICATED_ANONYMOUSLY, requires_channel: https }
      - { path: ^/*, roles: [ROLE_USUARIO, ROLE_RESELLER, ROLE_ADMIN], requires_channel: https }
  </code></pre>