0

i am trying to redirect the page using header location in xampp but it is not working and redirecting to localhost/dashboard

i used the following code for simple redirecting in localhost , i placed my site in htdocs/test/ and files in that are index.html and index.php, the index.php code is as follows

<?php 
      header("Location:/index.html");
 ?>

when i am trying to access http://localhost/test/index.php it is not going to localhost/test/index.html but it is redirecting to http://localhost/dashboard/

3 Answers3

2

Check in your php.ini file that output_buffering=On; then use this code to redirect to index.html

<?php 
ob_start();
     if (headers_sent()) {
   
    die("Redirect failed.");
}
else{
    exit(header("Location: index.html"));
}
?>

You can get details of ob_start from here http://php.net/manual/en/function.ob-start.php

Amit Ray
  • 3,445
  • 2
  • 19
  • 35
  • same problem even using it is there any problem with htaccess file – Gowrisankar Veluturla May 16 '16 at 11:42
  • Didi you check your php.ini file for output_buffering. Whether it is on or Off? If it is off then ob_start() wont work. Also did you replace /index.html to index.html? – Amit Ray May 16 '16 at 11:44
  • yes i checked php.ini file output buffering is ON , i just copied your code and placed and checked no work same problem – Gowrisankar Veluturla May 16 '16 at 11:46
  • Try this : Change the line exit(header("Location: index.html")); to exit(header("Location: index.html", true, 301)); Rename temporarily your htaccess file and restart your server. Check if it redirects properly now. – Amit Ray May 16 '16 at 12:08
0

i know your problem and this should fix it.

in your index.php

<?php 
header('Location: ./index.html');


?>

where ./ represents current directory

0

try:

<?php
echo "<script type=\"text/javascript\" language=\"javascript\">
        window.location.replace(\"index.html\");
      </script>";

?>