When you attempt to access a restricted page and are sent to the login page what is in the URL after the page name? There should be some data here that indicates what page was attempted to be accessed. It is this info that the gotopreviousurl setting makes use of.
As a test you could try taking out the successful redirect to see if this gets you to the restricted page originally accessed.
If you can please post back with a URL where I can give this a try myself to see if I can determine what is going wrong.