我有一些页面,遗憾的是它们被列在了谷歌搜索结果中。
现在我将这些页面作为iframe包含在其他页面的选项卡内。
如何将任何落在原始页面上的人重定向到新位置。
因此,page1.php 现在是 page_new.php#page1
原始页面已被剥离所有标题/页脚等内容,因此导航受到限制。
<script type="text/javascript">
if(top.location == self.location)
{
top.location.href = 'http://www.newurl.com/#map'
}
</script>
这似乎也有效。
所以感谢大家 :)
你能根据引荐人进行重定向吗?
<?php
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match("/site1.com/",$referrer)) {
header('Location: http://www.customercare.com/page-site1.html');
} elseif (preg_match("/site2.com/",$referrer)) {
header('Location: http://www.customercare.com/page-site2.html');
} else {
header('Location: http://www.customercare.com/home-page.html');
};
?>
来源: http://www.phpjabbers.com/redirect-based-on-referrer-or-ip-address-php2.html
另外,您可以在PHP中进行重定向,如果某个$_GET变量未设置。当您通过iFrame包含页面时,请始终设置它。这样,来自iframe页面的外部流量将被重定向到正确的页面。
顺便说一句,在iframe页面的头部内使用<meta name="robots" content="noindex, nofollow">
,以便将来不会出现在搜索引擎中。
在 PHP 中无法实现此操作,因为您要检查的是客户端(无论是否在 iFrame 中)。
JavaScript 在这里是您的朋友,正如 Maerlyn 所指出的那样。已经多次涉及了这个话题; 例如这个: 如何识别网页是在 iframe 中加载还是直接加载到浏览器窗口中?
采用 Greg 的建议并进行调整:
function inIframe () {
try {
return window.self !== window.top;
} catch (e) {
return true;
}
}
if (inIframe() !== TRUE) {
window.location = "http://example.com"
}
将 example.com 替换为您喜欢的页面的 URL。