using proxy instead of redirection with htaccess rewriteRule

半世苍凉 提交于 2019-12-10 17:19:00

问题


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.

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.

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

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]

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.

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.

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:


Have a look at these links / options:

  1. [P] flag:

    • http://httpd.apache.org/docs/current/rewrite/flags.html#flag_p
    • http://httpd.apache.org/docs/current/rewrite/proxy.html
  2. mod_proxy (possibly -- but I think #1 should be enough if it's on the same server):

    • http://httpd.apache.org/docs/current/mod/mod_proxy.htm


来源:https://stackoverflow.com/questions/9972985/using-proxy-instead-of-redirection-with-htaccess-rewriterule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!