我需要将可能被调用的所有子页面重定向到主页面(某些旧链接仍然在谷歌上),并且这些页面不再存在。
所以我在PHP中创建了一个函数,我在顶部的index.php中调用它,但Firefox和Chrome检测到无限循环。
我不知道它有什么问题。
这是我的功能:
<?php
function homepage() {
if ($_SERVER['REQUEST_URI'] == '/index.php' || $_SERVER['REQUEST_URI'] == '/index.html'
|| $_SERVER['REQUEST_URI'] == '/home.html' || $_SERVER['REQUEST_URI'] == '/default.html') {
header('location:http://www.website.com', true, 301);
}
}
?>
答案 0 :(得分:1)
http://www.website.com上的页面是什么,不会是index.php,所以您正在做的是将重定向发送到http://www.website.com/index.php然后检查再次将其发送至http://www.website.com/index.php,然后再次检查并将其发送至http://www.website.com/index.php,然后再次检查并将其发送至http://www.website.com/index.php,然后再次检查并将其发送至http://www.website.com/index.php,然后再次检查并将其发送到http://www.website.com/index.php
答案 1 :(得分:-1)
<?php
function homepage(){
if($_SERVER['REQUEST_URI']!='/index.php' and $_SERVER['REQUEST_URI']!='/index.html'
and $_SERVER['REQUEST_URI']!='/home.html' and $_SERVER['REQUEST_URI']!='/default.html'){
header('location:http://www.website.com', true, 301);
}
}
?>
现在,这应该是正确的:)