We have a Tomcat application from a vendor running with Apache in front of it, but we don't have access to the application code. We have our own single sign on wrapped around the application, so if a user clicks "Log Out" in the application, the user is taken to an unused "Login" screen. We would like to redirect that Login screen to the default Tomcat page, but I can't seem to get the syntax right.

I've tried a number of adjustments with no luck (escaping the /'s, etc). Does anyone have any ideas? I already have an HTTP to HTTPS redirect working (included in the directives below).

The "Logout" link goes through a few redirects, ultimately ending on: http://ourserver.com/abc/login

To keep things simple, we'd like to redirect any request for the login page to: http://ourserver.com/

<VirtualHost *:80>
RewriteEngine On
RewriteRule ^(.*)$ https://%{HTTP_HOST}$1 [R=301,L]
RewriteRule ^/abc/login$ / [L]

RewriteRule by default asumes that the result of the rewrite is a filesystem path. You are telling your server to serve /abc/login from the root of your filesystem, which is probably not what you want, nor would a properly configured server even permit it.

What you need to do is add the PT flag. Like this:

RewriteRule ^/abc/login$ / [PT]

The PT flag implies L, and will cause the server to consider the substitution result to be a URI, not a file system path.


Figured it out - turns out I was including the redirect directives under the wrong VirtualHost declaration.

In the example above, we have the redirect rule directly following the port 80 virtual host, whose only purpose is to redirect users to HTTPS. Our second rewrite rule would never be run once the user was over on VirtualHost *443.

Copying the above rewrite rule into our *443 declaration worked immediately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.