title: Redirect to referring url after login in wordpress sub-directory install
body: <p>I've read couple of previous post here but none of them is working in my case.. Basically, my blogging site is installed in a sub-directory of main website.. Main website in plain php and sub-directory is wordpress.. I allow users to read my blogs only after logged in. So, the thing is I frequently share the blog links in facebook where lots of new users come in from the link. </p>
  
  <p>Main website is installed in => example.com
  wordpress sub-directory in => example.com/blog</p>
  
  <p>As I'm using the custom template login page (login.php), whenever the non-logged in users comes- first they are redirected to example.com/blog/login. I'm using this function to redirect to login page: </p>
  
  <p>function redirect_user() {</p>
  
  <p>if ( ! is_user_logged_in() &amp;&amp; !is_page( 'login' ) ) {</p>
  
  <pre><code>$return_url = esc_url('http://www.example.com/blog/login');
  wp_redirect( $return_url );
  exit;
  
    }
  </code></pre>
  
  <p>}</p>
  
  <p>add_action( 'template_redirect', 'redirect_user' );</p>
  
  <p>It redirect fine, without problem.. Then the main task of redirecting to the referrer url, I'm using the similar code above to direct to every logged in users to the referring url irrespective or post or page.. Again in the functions.php</p>
  
  <p>if(is_user_logged_in())</p>
  
  <pre><code>    wp_redirect('' . $_SERVER["REQUEST_URI"]);
  </code></pre>
  
  <p>I thought they would work but can't seems to understand that referring url is appending the sub-directory name... For example; the above code show result as:</p>
  
  <p>example.com/blog/blog/blabla-blahblah.. You see the directory name is doubling..</p>
  
  <p>Anyone's advice would be highly appreciated..</p>