Cleaner handling of sessions (refs #334)

Removed 'redirected_from' after logging in. Better matching on login-url.
No trailing slash in cookie path (fixes #334)
Fix redirection on dedicated virtual hosts

The base_url is guaranteed to have a trailing slash, so don't include it
in the template; for virtual hosts, the base_url will be '/' and adding
'/upgrade' will result in '//upgrade', which is interpreted by browsers
as: 'http://upgrade/'.