Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have access to a folder on a web server in which I would like to put a .htaccess file to so that when a user visits www.somesite.com/myfolder/index.html they get shown the content of a page on another domain www.someothersite.com/blah/blah2/blah3/index.php?user=80338 which has a horribly long url, which I don't have access to that folder. However, I don't want the user to see this url in their browser, just for it to happen behind the scenes - I have tried reading some tutorials about the web and what I came up with is in the myfolder directory:

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

This seems to do the redirect, but I get the new url too, how can I stop this?

share|improve this question

2 Answers 2

Any external 301 or 302 redirect to the other page is going to be shown as the current location in the browser URL address bar. To achieve the result you want you have to keep the current parent document as your local index.html. So you have a couple of options to do that. (probably not a complete list...)

wrap the request in a ProxyPass

(this is probably the most transparent to the end user, as they have no way to detect that the page is actually remotely hosted, but is slightly more ball-achey)

To hide the redirect from the client, you would need to Proxy the request in the httpd.conf file for your VirtualHost like so;

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

To enable the above directives, you are going to need to install and enable the mod_proxy_http apache2 module, which is system dependent (e.g. yum, apt, a2enable)

However, you are going to get some interesting URL mapping issues, which you would have to tackle on a case-by-case basis, so to get this to work transparently would take some effort.

For example it depends how the links in your remote document are specified relative, or fully-qualified. You can fix each link and URL using ProxypassReverse and Mod_substitute rules.

Alternative: Load the page into an iframe (or use old skool frame)

You can use an iframe, which would be shown as the browser URL address bar, and load the remote document into an iframe with something like this;

<!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>

use old fashion frameset

<!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>
share|improve this answer
    
actually the latter probably makes more sense, given that it would "Just work" without too much faffing. –  Tom H May 29 '12 at 11:05

Setting up ProxyPass works, but I recently discovered you can do something similar with rewriting. Using the [P] flag at the end of your RewriteRule will cause the rewrite to be handled by mod_proxy. Basic example would be something like:

RewriteRule ^(.*)$ http://www.example.com/$1 [P]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.