Category Archives: PHP

URL Redirect with PHP

Reading Time: 1 minute

To create a url redirect with a simple php script.

1. Go into the directory where you want to place the redirect. (Normally your html folder)

cd /var/www/html

2. Create index.php file

touch index.php

3. Edit the file with whatever text editor you prefer. (I use nano, as i find it easier to use)

nano index.php

4. Use the script below. Of course change the URL to wherever you want it to go.

<?php

//* This is this basic code needs for a url redirect * //

header( 'Location: http://google.co.uk/' ) ;

?>

Note: that you will have to use the full URL, if you don’t the redirect will not work

Once you have saved and exited, you will be able to browser to your domain and you will see that you have been redirected to Google UK

Share this:
Share