用于重定向到主页的php函数提供了一个无限循环


function php for redirecting to homepage gives an infinite loop

我需要将所有可能被调用的子页面重定向到主页(一些旧链接仍在谷歌上),这些页面已经不存在了。

所以我用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);
    }
  }
?>

页面位于什么位置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

<?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);
        }
    }
?>

现在,这应该是正确的:)