views:

77

answers:

1

Hi All,

I have a requirement that I want to check the request headers and according to that I want to forward the incoming request to appropriate sub domain of my company.

For example:

request header A is coming then it goes to a.domain.com always (no matter request comes to a.domain.com or b.domain.com)

Similarly request header B is coming then it goes to b.domain.com always.

Although I can do this by changing my application (checking the request headers in it) and then forwarding the request but I want that instead of request reaching application server, it should be handled by web server at the first.

Is there something available (some way like CGI) which can handle IIS as well as Apache both as my company has sub domains hosting applications on these two.

Any help is greatly appreciated. Thanks

+1  A: 

In Apache you can use mod_rewrite to direct the request to another domain, something like the following perhaps:

rewriteEngine on
rewriteBase /
rewriteCond %{HTTP_HOST} ^A$
rewriteRule ^(.*) http://a.domain.com/$1 [L,R=301]

This needs to be scoped appropriately by putting it in a .htaccess file in the appropriate directory or in a site configuration element.

IIS (depending on the version) also supports a rewrite module. For IIS 6 you can look at IIRF which has a syntax similar to mod_rewrite. For IIS 7 take a look at the URL Rewrite Module which has a simple GUI that imports mod_rewrite rules.

joshperry
What I exactly want to do is to identify the request is coming from Mobile or from Normal Browser thus needs to check HTTP_USER_AGENT. I checked rewriteCond will do that stuff for me in Apache. IIS I need to check. Anyways thanks for the help.
Beginner
Yes, I see what you mean; like you said, %{HTTP_HOST} can easily be replaced with %{HTTP_USER_AGENT} and the RegEx can be modified to match a specific user agent string.
joshperry