Create a PHP redirect


There are several ways to redirect a URL. This is useful for redirecting requests from their main domain to another directory under that domain, such as directing requests for to This can be done using a .htaccess file. However, it's also possible to redirect using PHP.

This article gives a quick example of creating a redirect using PHP.

Creating a simple redirect in PHP

  1. Create a file named index.php. You can do this using an FTP client such as Filezilla or via SSH. View the following articles for instructions on how to create it (depending on if you're using an FTP client or SSH):
  2. Make sure the file is in the domain's directory. This directory is the one specified when adding the domain to your panel. View the Changing the web directory article for instructions on how to view this.
  3. In this index.php file, add the following line of code:
    <?php header("Location:"); ?>

Remember to change the sample URL to the URL you want the site to forward.

You'll then have a simple and quick redirection that you can use to redirect an HTTP request to any URL seamlessly.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?