url重写到不同的域

我有权访问Web服务器上的一个文件夹,我想在其中放置一个.htaccess文件,以便当用户访问www.somesite.com/myfolder/index.html时,他们会看到另一个域中的页面内容www.someothersite.com/blah/blah2/blah3/index.php?user=80338其中有一个可怕的长url,我没有访问该文件夹。 但是,我不希望用户在浏览器中看到这个URL,只是为了在幕后发生 – 我曾尝试阅读一些有关Web的教程,而我想到的是在myfolder目录中:

RewriteEngine On RewriteRule ^index\.html$ http://www.someothersite.com/blah/blah2/blah3/index.php?user=80338 [QSA,L] 

这似乎做了redirect,但我也得到了新的url,我怎么能阻止呢?

设置ProxyPass的作品,但我最近发现你可以做一些类似的重写。 在你的RewriteRule的末尾使用[P]标志将导致重写被mod_proxy处理。 基本的例子会是这样的:

 RewriteRule ^(.*)$ http://www.example.com/$1 [P] 

任何外部301或302redirect到另一个页面将被显示为浏览器URL地址栏中的当前位置。 为了达到你想要的结果,你必须保留当前的父文档作为本地的index.html。 所以你有几个select来做到这一点。 (可能不是一个完整的清单…)

将请求包装在ProxyPass中

(这对于最终用户来说可能是最透明的,因为他们没有办法检测到页面实际上是远程托pipe的,但是略微更具球性)

为了隐藏来自客户端的redirect,您需要像这样在httpd.conf文件中为您的VirtualHost代理请求;

  <Location /index.html> ProxyPass http://www.someothersite.com/blah/blah2/blah3/index.php?user=80338 </Location> 

要启用上述指令,您将需要安装并启用mod_proxy_http apache2模块,该模块依赖于系统(例如,yum,apt,a2enable)

但是,您将得到一些有趣的URL映射问题,您必须逐个解决这个问题,为了使其透明地工作,需要付出一些努力。

例如,它取决于如何指定远程文档中的链接是相对的,还是完全限定的。 您可以使用ProxypassReverse和Mod_substitute规则修复每个链接和URL。

替代方法:将页面加载到iframe (或使用旧的skool框架)

你可以使用一个iframe ,它会被显示为浏览器的URL地址栏,然后将远程文档加载到一个类似iframe的iframe中 ;

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="EN"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Full Page IFrame</title> <style type="text/css"> html {overflow: auto;} html, body, div, iframe {margin: 0px; padding: 0px; height: 100%; border: none;} iframe {display: block; width: 100%; border: none; overflow-y: auto; overflow-x: hidden;} </style> </head> <body> <iframe id="tree" name="tree" src="http://www.someothersite.com/blah/blah2/blah3/index.php?user=80338" frameborder="0" marginheight="0" marginwidth="0" width="100%" height="100%" scrolling="auto"></iframe> </body> </html> 

使用旧的时尚框架

 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html> <head><title>My First Frame Page</title> </head> <frameset cols="100%"> <frame src="http://www.page3.com"> </frameset> </html>