title: How to redirect users to login page when users try to access assets using direct URL
body: <p>So I have a full fledged working website where user can login and register. Now when a user login i create a user session and use that to maintain the login state.</p>
  
  <p>Now my site has few video content which is hosted in my server. These are suppose to be accessible only when the user is logged in. But right now anyone having the direct link to the media is able to view them without login. </p>
  
  <p>Current webiste folder structure looks like this:
  <img src="https://i.stack.imgur.com/5EEKB.png" alt="enter image description here"></p>
  
  <p>So i am trying to solve 2 problems:</p>
  
  <ol>
  <li>If user try to access the link directly and not logged in should be redirected to login page.</li>
  <li>If the user is logged in already he should be able to view the resource even with direct links?</li>
  </ol>
  
  <p>What approach do you suggest? I don't want to stop user using <code>.htaccess</code> force authentication as some mobile browser don't support it and would like to redirect user to login page for un auth access.</p>