标头位置在服务器上不起作用,但适用于localhost

I cant get header location to work on my server, but when i run the script at localhost, everything works fine. It seems the server does not run this line.

header('location:index.php');

Server running linux stack with php 7.2, localhost is running xampp (osx) with php 7.3.

I have several projects on the same server with header location, and those are working fine.

you can use

echo "<script> window.location.href = 'index.php'; </script>";

Check the path of your index.php

Also you can try to add this before header.

ob_start(); then after that you can exit()

header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP

Linux server is case sensitive try with uppercase Location this. its better to stop script after the header location so no other script will run afterwards.

header('Location: index.php');  
exit;

header best works with absolute URL's, try using http://...../index.php rather than just the filename index.php and since it is index.php use the parent folder, and with the exit; command for example, if

     Location('http://www.slyde.com/index.php'); 
     exit;
     //should be 
     Location('http://www.slyde.com');
     exit;

and so with relative folders.

     Location('http://www.slyde.com/app/index.php');
     exit;
     //should be 
     Location('http://www.slyde.com/app');
     exit;

i hope this works..

alternative to header() you can use :

echo '<script> location.replace("http://yoursite.com/yourpage.php");</script>';