2

I am new to php and I faced this problem while redirecting to other php files. To make my question clear I created two php files. first.php and second.php.Both this files are found in /var/www/test/. This is the code in first.php

<?php
$url = "localhost/test/second.php";
header("Location:$url");   ?>

This is the code in second.php

<?php
echo("this is the second page"); ?>

And when I browse to first.php file I got this in my Firefox browser.

The requested URL /test/localhost/test/second.php was not found on this server.

test/ is added to the header string, which is clear as you can see. Thank you.

  • possible duplicate of: http://stackoverflow.com/questions/11072042/headerlocation-redirect-works-on-localhost-but-not-on-remote-server or http://stackoverflow.com/questions/1284338/redirect-from-localhost-to-localhost-abc – gen Feb 13 '16 at 12:50

1 Answers1

0

The server is appending your parameter to the current working directory. To make it clear to your server, that this is an entirely new URI, prepend your parameter with http://. That way it becomes an absolute URI:

$url = "http://localhost/test/second.php";

If you have problems with localhost not being resolved properly, refer to the questions linked by @gen.

chucktator
  • 1,828
  • 12
  • 16