I\'d like to send a response code of 401 if the requesting user is not authenticated, but I\'d also like to redirect when the request was an HTML request. I\'ve been finding
You can certainly send a Location: /login header alongside with your 401 page, however, this is ill-advised, and most browsers will not follow it, as per rfc2616.
One way to do overcome this, is to serve alongside with your 401 page: