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

The following two tabs change content below.

Keeran Marquis

Network Engineer
Keeran Marquis is a Network Engineer. His main goal is to learn everything within the Networking field, pick up a little bit of scripting, be a poor man sysadmin and share whatever he knows! All Posts are his own views, opinions and experiences, no guarantees they will work for you but point you in the right direction ๐Ÿ™‚
Share this:
Share

2 thoughts on “URL Redirect with PHP”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.