diff --git a/trac/web/auth.py b/trac/web/auth.py
--- a/trac/web/auth.py
+++ b/trac/web/auth.py
@@ -35,6 +35,7 @@
 from trac.web.api import IAuthenticator, IRequestHandler
 from trac.web.chrome import INavigationContributor
 from trac.util import hex_entropy, md5, md5crypt
+from trac.util.text import unicode_urlencode
 
 
 class LoginModule(Component):
@@ -94,11 +95,13 @@
     # IRequestHandler methods
 
     def match_request(self, req):
-        return re.match('/(login|logout)/?$', req.path_info)
+        return re.match('/(?:login(?:/.*|$)|logout/?$)', req.path_info)
 
     def process_request(self, req):
         if req.path_info.startswith('/login'):
             self._do_login(req)
+            if len(req.path_info) > 7:
+                self._redirect_args(req, req.path_info[6:], req.args)
         elif req.path_info.startswith('/logout'):
             self._do_logout(req)
         self._redirect_back(req)
@@ -195,6 +198,14 @@
 
         return row[0]
 
+    def _redirect_args(self, req, dest, args):
+        """Redirect to the given URL with the given arguments."""
+        dest = req.base_path + dest
+        if args:
+            dest += "?" + unicode_urlencode((k, v) 
+                for k in args.iterkeys() for v in args.getlist(k))
+        req.redirect(dest)
+        
     def _redirect_back(self, req):
         """Redirect the user back to the URL she came from."""
         referer = req.get_header('Referer')

