Gowrisankar Veluturla
Gowrisankar Veluturla

Reputation: 43

PHP Header Location is not working in localhost xampp?

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/

Upvotes: 0

Views: 6244

Answers (3)

Egi Samsul Muarif
Egi Samsul Muarif

Reputation: 9

try:

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

?>

Upvotes: 0

user4796734
user4796734

Reputation:

i know your problem and this should fix it.

in your index.php

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


?>

where ./ represents current directory

Upvotes: 0

Amit Ray
Amit Ray

Reputation: 3485

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

Upvotes: 2

Related Questions