title: frontend login with redirect to target page and 404 in TYPO3
body: <p>i am fighting with the following problem in an installation with many restricted pages. Many of this pages are linked from outside, from other sites. </p>
  
  <p>So i need the following possibilites: </p>
  
  <ol>
  <li><p>when the user is not logged in and the target page exists he should be redirected to a login page and then again redirected to the target page. </p></li>
  <li><p>when the user is not logged in but the target page does <em>not</em> exist (= 404) then the user should be redirected to the login page and then aftrer login redirected to a 404 page. </p></li>
  </ol>
  
  <p>Number 1 I can achieve with redirecting every 404 in the install tool to my login page (/?id=1234). But this ends in an infinite loop when the target page does not exist. The user is again and again redirected to the login page ... </p>
  
  <p>Any ideas how to manage this?
  Thanks!</p>