Is a masked 307 redirect for a domain possible?

It's impossible to externally redirect (3xx status) and mask the request (ie. keep the original URL in the address bar). To the end user, a "masked" URL just looks like an ordinary (200 OK) request. A 3xx response is not.

iFrames are the only way to retain the URL in the address bar

However, iframes are not necessarily the only way to mask the URL. Assuming this is a cross-domain request, then the request could be proxied?

...his free-hosted-website.

Well, in this case, an iframe might well be the only way to handle this!


Part of me thinks there must be something else to this? Where are you wanting to "redirect" from?


A masked 307 redirect is not possible. You can either redirect or mask but not both together. The code you posted in your question will achieve the redirect if thats the solution you want, but I don't understand why you would want a 307 redirect, which just tells the browser it can't switch between GET/POST method. Best/common practice is to stick to 301 for permanent redirects and 302 for temporary redirects unless this might be used on a URL where POST data is expected. A 307 redirect will not in itself apply any masking - a redirect header whether 301, 302 or 307 will change the browser address.

While most website masking is setup and managed using hosting or domain name control panels rather than people writing source code for it themselves, the method used most today is still the old HTML4 frameset tags which all major browsers still support:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" 
  "http://www.w3.org/TR/html4/frameset.dtd">
<html>
  <frameset rows="100%">
    <frame src="http://www.masked-domain.com/" />
  </frameset>
</html>

To mask by proxying requests you could use PHP code similar to this in index.php:

<?php
$sOldURL = sprintf( 'http://www.masked-domain.com/%s', $_SERVER['REQUEST_URI'] );
echo( @file_get_contents( $sOldURL ));
exit;

and then redirect all requests to that index.php file using a .htaccess file:

RewriteEngine On
RewriteRule ^(.*)$ /index.php/$1 [L]