5

We have a web application (JQuery and Spring) running on weblogic app server. There is a apache http server in front of the app server. All incoming requests will come through the web server and reaches the app server.

Now we have a requirement that we have to verify for a value in the incoming http request header and if present, the request has to sent to the app server. If not we have block the request and in turn display a static error page to the end user.

I want to know whether we can implement this logic in the apache http server. Please advice.

1
  • Please read our FAQ, webmasters.stackexchange.com/faq to learn more about what questions are appropriate for our site. This is a great question, it just belongs on Stack Overflow. Dec 10, 2011 at 14:01

1 Answer 1

2

You can do this with mod_rewrite. You didn't include what your exact set up is, but if you have a mod_proxy type config you just want to make sure that the rewrites don't interfere with the passage of normal traffic. In a general sense, in your Apache config, you would:

  • Turn on rewrite
  • Check for the condition
  • Apply the rewrite rule based on the conditions

To give a really simple example, if you were looking for a key in the query string, and forbidding access (403) if it was not present, you would do something like this:

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} !somekey
RewriteRule ^.*$ - [F,L]

This can be as complicated as you wish really, you can chain conditions together (implicit AND or an explicit or witht he [OR] flag) and you can serve an actual page rather than a forbidden message.

As always, back up your config before tinkering, and it might be a good idea to test this out with .htaccess (though for performance reasons it's better to move it to the actual config for production loads).

The rewrite documentation is a great resource too:

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

It really is quite good documentation. For some pointers - you will want to look up the flags ([L] = last; [P] = treat as a proxied request; [F] = forbidden etc.) and you will need someone generally familiar with regular expression syntax

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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