2012-10-29 59 views
0

我有以下情形:mod_rewrite的:重定向本地请求到远程服务器

  • http://remote/webapp
  • 本地机器内部企业网络
  • 它们之间
  • 公司代理
  • 运行某些Web应用程序的远程服务器Apache与我的本地机上运行的mod_rewrite

我想有mod_proxy将http://localhost/webapp?someparams之类的每个请求重写为http://remote/webapp?someparams

目前,我有以下的httpd.conf:

DocumentRoot "C:/Apache2.2/htdocs" 

<Directory /> 
    RewriteEngine On 
    RewriteRule ^(.+) http://remote/$1 
    Options FollowSymLinks 
    AllowOverride All 
    Order deny,allow 
    Deny from all 
</Directory> 

导致的mod_rewrite转化成http://localhost/webapp?someparamshttp://remote/C:/Apache2.2/htdocs/webapp?someparams

如何配置mod_rewrite的正确处理呢?

+0

我认为这就是所谓的反向代理,你可能想看看 –

+0

我认为从所有的拒绝都是罪魁祸首,允许所有人都会工作我认为,你可以尝试一次也是,在这里你的期望是不可预测的,你在URL中使用Windows绝对路径,真的无法找出想要的东西 –

+0

Windows绝对路径出现在URL中的事实是由于mod_rewrite配置错误造成的,这就是我想要避免的。 – s4nk

回答

0

谢谢乔恩为灵感,最终的mod_proxy + mod_rewrite的工作:

# Global context 
RewriteEngine On 
RewriteRule ^(.+) http://remote/$1 [P] 
ProxyPassReverse/http://remote/ 

我知道,这是一个简单和粗糙的解决方案,但适合我的目的。

0

因为它看起来像您可以访问虚拟主机/服务器配置,你应该沟mod_rewrite的,只是使用的mod_proxy:

ProxyPass /webapp http://remote/webapp 
ProxyPassReverse /webapp http://remote/webapp 

和摆脱2个mod_rewrite的行(这是重定向,不进行代理)的:

RewriteEngine On 
RewriteRule ^(.+) http://remote/$1 

需要注意的是,如果你有饼干,你可能需要反向映射他们的domains.using ProxyPassReverseCookieDomain


另外:

的Windows绝对路径URL中出现的事实是,由于mod_rewrite的配置错误,这就是我试图避免

这是不是mod_rewrite的错误配置。当您将重写规则放在<Directory>中时,文件路径将用于匹配而不是URI路径。根据mod_rewrite documentation

什么是匹配?

VirtualHost上下文中,模式将首先与主机名和端口之后以及查询字符串(例如“/app1/index.html”)之前的URL部分进行匹配。

Directory和htaccess的上下文中,模式最初将针对文件系统路径匹配,移除导致所述服务器向所述当前RewriteRule(例如,取决于“APP1/index.html中”或“的index.html”前缀后指令在哪里定义)。

+0

与域名一起使用的ProxyPass导致“DNS查找失败”错误,我无法使用IP而不是域名。但是,谢谢! – s4nk

相关问题