我正在尝试构建一个网站,让您可以查看和操作来自任何其他网站的任何页面的数据。为此,我必须绕过“ Allow Origin”问题:我正在加载其他域的内容,iframe 并且必须使用从我的域下载的 javascript 来操作其内容。
我的第一次尝试是自己编写一个简单的代理,通过一个用 Java 编码的服务器代理请求其他域页面,该代理不仅提供内容,还重建内容中的链接(src 和 href ),以便这些链接引用的内容也得到通过我手工制作的代理下载。结果还不错,但在 css 和脚本中的 url 有问题。
就在那时,我意识到mod_proxy_html应该完全完成所有这些工作。问题是我无法弄清楚如何让它按预期工作。
假设我的服务器在 my-domain.com 中运行并代理和转换来自另一个域的内容,我会发出这样的请求:
my-domain.com/proxy?url=http://another-domain.com/some/content
Run Code Online (Sandbox Code Playgroud)
我想通过以下方式mod_proxy_html提供内容并重写以下 URL http://another-domain.com/some/content:
another-domain.com: 没有重写/other/content->/proxy?url=http://another-domain.com/other/contentother/content->/proxy?url=http://another-domain.com/some/content/other/content../other/content->/proxy?url=http://another-domain.com/some/other/contenturl 应该在运行时指定,而不是配置时。
这可以通过 mod_proxy_html 实现吗?谁能提供一个简单的工作配置开始?
编辑 1-第一种方法
以下站点配置适用于在任何地方都使用绝对 url 的站点,例如http://www.huffingtonpost.es/. 你可以在本地主机上尝试这个配置:http://localhost/asset/http://www.huffingtonpost.es/
<VirtualHost *:80>
ServerName localhost
LogLevel debug
ProxyRequests off
RewriteEngine On
RewriteRule ^/asset/(.*) $1 [P]
ProxyHTMLURLMap $1 …Run Code Online (Sandbox Code Playgroud)