Codeigniter redirect changing on login page
===

I am trying to redirect users to the page they were viewing before attempting to login. For example, if they were looking at baseurl/people/abraham_lincoln and then decided to log in, after they login they would be redirected to baseurl/people/abraham_lincoln. The weird thing is that it is working for some URLs and not others. For some URLs, I am getting "javascript/jsFunctions.js" appended as the URL instead of the URL they were previously on.

At the top of every controller, I set a session variable to do my redirect:

    $this->session->set_userdata('Redirect', current_url());

I am printing this session variable to the top of my controller and at the top of my log in view for testing purposes. Here are a few results I am receiving when I go to my login.

**An example of a URL that's working:**

URL I attempt to log in from:

    baseURL/people
What gets printed at the top of my controller as my Redirect session variable:

    baseURL/people
What gets printed at the top of my log in view as my Redirect session variable:

    baseURL/people

**An example of a URL that's not working:**

URL I attempt to log in from:

    baseURL/people/abraham_lincoln
What gets printed at the top of my controller as my Redirect session variable:

    baseURL/people/abraham_lincoln
What gets printed at the top of my log in view as my Redirect session variable:

    baseURL/people/javascript/jsFunctions.js

I'm not sure if it matters, but I am also routing some of these URLs from the routes.php file:

    $route['people/(:any)'] = "people/index/$1";
    $route['people/(:any)/(:num)'] = "people/index/$1/$2";

I have tried to build my session variable many different ways, including:

    current_url()
    base_url().uri_string()
    base_url().$this->uri->segment(1)....
    base_url().$this->uri->rsegment(1)....

If anyone can think of why I'm getting those javascript variables instead of the URL I'm looking for I would appreciate any input.

Thanks!

P.S. I forgot to mention that if I refresh a page that isn't working, for example the abraham_lincoln page, and then go to login, I receive the correct Redirect session variable. Almost like it isn't getting set correctly the first time through, but don't know how I can solve this since I have tried setting the session variable both at the very top and right before the views are loaded.