Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  Know How to Set a PHP Redirect?
Top Scroll

Know How to Set a PHP Redirect?

 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!

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.