Knowledge Base
MilesWeb / How-Tos

Know How to Set a PHP Redirect?

Approx. read time : 2 min

Overview

Some of the most famous websites in the world are powered by PHP. If your website is built in PHP, it’s essential to learn about the new functionality to your website, which is the PHP redirect.

In this guide we’ll understand how to create a PHP redirect.

Creating a Redirect in PHP

Create a file name index.php in the directory you want to redirect from:

For eg: Here we are redirecting index.php to test.com.

<?php header(“Location: http://www.redirect.to.test.com/”); ?>

Here “http://www.redirect.to.test.com/” is the URL you want the users to be redirected to.

This can even be a file. Then it looks like:

<?php header(“Location: anotherDirectory/anotherFile.php”); ?>

Also, make sure you change the sample URL to the URL you would like the site to forward.

Note: The above files can be of any type, but should not be limited to Python, HTML, CGI, Perl and even the CGI programs.

Conclusion

PHP redirects can help search engines to navigate smoothly and securely between the pages on your website. Setting redirects in PHP is easy, and all because of the header () function.

Hope this article helps!

Nehal Khatri
Nehal is an ardent content writer. She's passionate about crafting content that's simple but adds value. Her insatiable interest in writing has allowed her to explore her skills. She is adept and can write for different types of content formats.