How to configure Apache web server to handle Tomcat 302 response code?

Posted on 2011-05-03
Last Modified: 2013-12-24
Our application is hosted in Apache 2.2.10 Web server. Load balancing is configured in virtual host.

Usual URL requests of the application are of the kind /InfoViewApp/?0.2322. But, after a patch, the URL structure has a error : /InfoViewApp?0.621367810784860 The ' / ' is missing before the ' ? '.

What happens When the requests are forwarded directly to Tomcat?

1. The URL request that is problematic has now got a request similar to below:


But, the original request should be /InfoViewApp/?0.6213678107848606

2. Because of this, HTTP response code 302 is thrown (i.e., moved temporarily).

3. The client side browser (eg., internet explorer) is capable of handling the 302 response codes :

The URL is then corrected by the browser and request is redirected as /InfoViewApp/?0.6213678107848606. So, the correct request yields a HTTP response code of 200 (i.e., successful response)

So what happens when requests go via Apache?

1.    The invalid URL - /InfoViewApp?0.6213678107848606 is passed on to Apache.

2.    Apache passes this request to Tomcat via load balancer.

3.    Tomcat throws 302 response code back to Apache(in this case not passed on directly to the browser that can handle 302).

4.    But, the problem lies that : Apache redirect for response code 302 is not configured in the config file. So connection to the server is reset and we get PING error in our browser. Only, if this is configured, Apache can handle the 302 code without throwing error.

How to configure the redirect?

I tried out the following with no success :

RewriteEngine on

RewriteRule ^/InfoViewApp(\?.*)$ https://domain/InfoViewApp/$1 [R=302,L]

Please help in sorting out this issue.

Question by:harish_ravi
    LVL 5

    Accepted Solution

    You seem to want to catch wrong URLs, e.g.: /infoViewApp?0.6213678107848606 Right ones (with the added / ) should pass:

    RewriteRule ^/InfoViewApp$ https://domain/InfoViewApp/

    The querysting (question mark and everything behind it) are not matches by rewriterules. In your case, they don't have to be matches, just passed on. Add a QSA (querystring attach) to the rewriterule and a L (do an immediate rewrite, 302 is default so R is not needed):

    RewriteRule ^/InfoViewApp$ https://domain/InfoViewApp/ [L,QSA]

    Author Comment

    Thanks a lot Simon,

    This seems to work now.

    Anyway let me o some more testings and then we can conclude :)


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    One of the biggest challenges facing freelancers is balancing multiple projects and deadlines. Organizational skills and time management are key to keeping up with projects and staying on track. Luckily, we’ve curated seven tools to help you focus o…
    Whether you believe the “gig economy,” as it has been dubbed, is the next big economic paradigm shift ( or an overstated trend (…
    Articles on a wide range of technology and professional topics are available on Experts Exchange. These resources are written by members, for members, and can be written about any topic you feel passionate about. Learn how to best write an article t…
    Introduction to GIMP:  GNU Image Manipulation Program. It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now