To create a url redirect with a simple php script.

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

cd /var/www/html

  • Create index.php file

touch index.php

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

nano index.php

  • 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/' ) ;

?>

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 on LinkedIn
Share on Reddit