开发者

Forward one domain to another based on request header

开发者 https://www.devze.com 2022-12-10 14:44 出处:网络
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.

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 ava开发者_如何学Cilable (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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消