使用代理而不是使用htaccess rewriteRule进行重定向

问题描述:

我正在开发一个Web应用程序,对于静态文件,我只是在localhost上使用apache,而后端位于在localhost:5984上运行的couchdb实例上.

I'm developing a webapp and for the static files I'm simply using apache at localhost while the backend is on a couchdb instance running at localhost:5984.

Web应用程序始终与后端的文件进行交互.因此,由于跨域策略,尝试在apache上测试所有对localhost:5984的文件请求时会发生什么事情,因此,要使该文件正常工作的唯一方法是通过设置忽略该标志的浏览器来启动它.

The webapp interacts with files from the backend all the time. So what is happening when trying to test on apache all file requests to localhost:5984 are getting blocked due the cross-domain policy so the only way to get that working is starting the browser by setting flags to ignore that.

但是,当我尝试在ipad或iphone等移动设备上测试应用程序时,我再次陷入困境.

But again I get stuck when trying to test the app on mobile such ipad or iphone.

目前,我在.htaccess文件中拥有此文件.

Currently I have this on my .htaccess file.

RewriteEngine  on

# these are 302 http redirections instead of serving as a proxy
RewriteRule auth http://localhost:5984/auth [L]
RewriteRule db/([\s\S]+) http://localhost:5984/db/$1 [L]
RewriteRule send/([\s\S]+) http://localhost:5984/send/$1 [L]

# these are just redirections to static files and work great
RewriteRule ^([a-z/.]+) _attachments/$1 [L]
RewriteRule ^$ _attachments/ [L]

您可以看到,不幸的是,我真的对如何处理apache配置一无所知. 但是现在发生的事情是,对于其中的某些规则,apache只是重定向页面,而不是将其提供为代理服务器,这会导致跨域问题.

As you can see I have really no idea on how to deal with apache configuration unfortunately. But what is happening right now is that for some of these rules apache is simply redirecting the page instead of provide it as a proxy server which causes the issue with cross-domain.

同样在第一个auth规则上,我发送POST和DELETE请求,这些请求作为重定向而不是代理,它不会传递被发布的数据.

Also on the first auth rule I send POST and DELETE requests which as a redirection instead of proxy it won't pass the data being POSTed through.

所以我想实现的是激活某种功能(如果存在),这将使apache像在localhost域上一样简单地呈现页面,而不是重定向它. (我将其命名为代理,但这也许不是正确的用语,对于命名法中的任何错误,我们深表歉意.)

So what I would like to achieve is to activate some kind of feature (if it exists) which will make apache simply render the page as it was on the localhost domain instead of redirect it. (I named this a a proxy, but perhaps that's not even the right term, sorry for any mistake committed with the nomenclatures).

有可能实现这种行动吗? 预先感谢

Is is possible to achieve such action? Thanks in advance

看看这些链接/选项:

  1. [P]标志:

  1. [P] flag:

  • http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
  • http://httpd.apache.org/docs/current/rewrite/proxy.html

mod_proxy (可能是 ,但是我认为#1如果在同一台服务器上就足够了)

mod_proxy (possibly -- but I think #1 should be enough if it's on the same server):