根据apache

时间:2016-05-29 04:15:16

标签: apache .htaccess mod-rewrite

我必须根据原始apache服务器上收到的请求将请求重定向到2个不同的服务器(Server-A和Server-B)。

Server-A也是另一个apache服务器,Server-B是weblogic服务器。我使用weblogic代理插件指令重定向Server-B的请求。因此,只有具有/ console或/ mywlsapp上下文的请求才应重定向到weblogic服务器。应将所有其他请求重定向到Server-A。

我尝试使用ReWrite Cond排除WLS上下文。但它没有奏效。

这是我的重写规则。你能帮我解决这个问题吗?

RewriteCond %{REQUEST_URI} !^/console/
RewriteCond %{REQUEST_URI} !^/mywlsapp/
RewriteCond %{HTTP_HOST} ^mycustomapp\.mycompany\.com:7090 [OR]
RewriteCond %{HTTP_HOST} ^http://mycustomapp\.mycompany\.com:7090
RewriteRule ^(.*) http://Server-A.mycompany.com/$1 [P]

<Location /console>
WLSRequest On
SetHandler weblogic-handler
WebLogicHost Server-B
WebLogicPort 7110
</Location>

<Location /mywlsapp>
SetHandler weblogic-handler
WebLogicHost Server-B
WebLogicPort 7112
</Location>

1 个答案:

答案 0 :(得分:1)

What I think you might want is this

RewriteCond %{REQUEST_URI} !^/console/
RewriteCond %{REQUEST_URI} !^/mywlsapp/
RewriteCond %{HTTP_HOST} ^mycustomapp\.mycompany\.com$
RewriteCond %{SERVER_PORT} ^7090$
RewriteRule ^(.*)$ http://Server-A.mycompany.com/$1 [R=301,L]

This should 301 redirect

http://mycustomapp.mycompany.com:7090/foo

to

http://Server-A.mycompany.com/foo

However, all of the above conditions must be fulfilled for this redirect to happen, in clear English:

  1. URI may not begin with /console/ or /mywlsapp/ AND
  2. Host has to be exactly mycustomapp.mycompany.com AND
  3. Port has to be exactly 7090

Please note that e.g. http://mycustomapp.mycompany.com:7090/console will not be redirected, but http://mycustomapp.mycompany.com:7090/console/ will.