tags:

views:

500

answers:

2

I have placed an index.php file in the root of my web site (http://localhost).

I want to redirect this page (http://localhost) to http:/localhost/abc - when I visit http://localhost, I want the user to go to http://localhost/abc.

What do I need to do to my index.php file?

+5  A: 

Hi,

What about something like this in your first index.php :

header('Location: http://localhost/abc');
exit;

(BTW, you forgot some slashes after 'http:' in your OP ^^ )

Anything/anyone that comes to this first page will be redirected to the 'abc' one.

See header, for more informations.

One thing : make sure nothing is send to the ouput before calling the header function, else you might get an error : headers cannot be sent if any output (like HTML code, or even white spaces !) has already been generated.

Pascal MARTIN
I've fixed the slashes, etc. for the OP.
Lucas Jones
thanks! (Ergh, I often fixe some posts for stuff like that, but I just simply didn't think about it this time :-( )
Pascal MARTIN
A: 

You want to use an HTTP Redirect using the header command in PHP.

So, in order to redirect someone, you must put this command before any whitespace in your program (spaces or HTML outside of the PHP tags):

<?php 
    header("Location: http://localhost/abc");
?>

This will send a Redirect Header to the browser, which will then redirect the user.

Because it is up to the 'browser' to redirect the user, you want to make sure no more PHP is outputted onto the screen, so use either exit or die to make sure no more code is ran

<?php 
    header("Location: http://localhost/abc");
    exit();
?>

or,

<?php 
    header("Location: http://localhost/abc");
    die("Your browser does not support redirection. Please go to http://localhost/abc.");
?>
Chacha102