There are many instances where redirection saves a lot of time. You can create a redirection to forwards users to a page which is translated for their locale. You can use redirection for affiliate link and you can also use redirection to avoid non-local folks to English version of your site. You can also redirect users from 404 page to homepage in order to help in SEO. There are many other uses of redirection script, it’s all upto you to use it in a way that gets your job done.
PHP redirects being a server side script works on all browsers and you don’t have to worry about browser standards. Redirection is quick and distraction free as you’re not wasting time by showing them some demo page in between the redirection. In this tutorial we’re assuming that you’re creating redirection on your 404 page. You can use the following code to redirect search engines and users to homepage.
Code:
<?php header('Location:http://yahoo.com'); ?>
You can replace the yahoo with some other page of your site. You can also use specific 404 page or archive page which most of the websites use to redirect users. Archive page or sitemap pages are more useful as they let visitors make decision about where to visit next from the redirected page.
Note: While running this php page make sure you’re not placing this code in < body > tag. Make this page purely php page without any other code in between and before or after the code. This should be the only code that needs to be executed in order for this example to work. If you’re using php designer 7 onwards then you may notice that redirection example may not work in the IDE. For some strange reasons it doesn’t work inside IDE.