大网数据广告活动
网站运营与故障问答

Is a masked 307 redirect for a domain possible?

· 52CE 我爱测

I've been asked to create a 307 redirect for a domain, ensuring it is "masked". i.e. keep the original URL in the address bar. There isn't a lot of info available about 307 (as opposed to 301/302) redirects, but from my investiga…

问题原文

原帖链接 · Rob · CC BY-SA 3.0

I've been asked to create a 307 redirect for a domain, ensuring it is "masked". i.e. keep the original URL in the address bar.

There isn't a lot of info available about 307 (as opposed to 301/302) redirects, but from my investigations it seems that 307 redirects are similar to 302 redirects.

I have a feeling what I've been asked to do is impossible, and for now I have created an iframe which loads up his free-hosted-website.

Before I look an idiot and go back to him, and tell him iFrames are the only way to retain the URL in the address bar, can someone confirm this.

Alternatively, tell me how to create a 307 redirect. I assume it's something like this.... But how can it be masked?

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=307,L] 

已采纳解答

原帖链接 · richhallstoke · CC BY-SA 3.0

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]

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-03-02)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。