根据请求标头将一个域转发到另一个域

发布于 2024-08-10 23:15:09 字数 347 浏览 3 评论 0原文

我有一个要求,我想检查请求标头,并根据要求将传入请求转发到我公司的适当子域。

例如:

请求头 A 到来,然后它总是转到 a.domain.com(无论请求到达 a.domain.com 还是 b.domain.com),

同样,请求头 B 到来,然后它去 b.domain。 com 总是。

虽然我可以通过更改我的应用程序(检查其中的请求标头)然后转发请求来做到这一点,但我希望请求不到达应用程序服务器,而应该首先由 Web 服务器处理。

是否有可用的东西(某种方式,如 CGI)可以处理 IIS 和 Apache,因为我的公司在这两者上有托管应用程序的子域。

非常感谢任何帮助。谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

倾听心声的旋律 2024-08-17 23:15:09

在 Apache 中,您可以使用 mod_rewrite 将请求定向到另一个域,可能类似于以下内容:

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

需要通过将其放入适当目录或站点配置元素中的 .htaccess 文件中来适当限定范围。

IIS(取决于版本)还支持重写模块。对于 IIS 6,您可以查看 IIRF ,它的语法与 mod_rewrite 类似。对于 IIS 7,请查看 URL 重写模块,它具有一个可导入 mod_rewrite 规则的简单 GUI 。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文