How to create a PHP redirect

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

This article gives you a quick example of how to create a redirect using PHP.

Creating a simple redirect in PHP

  1. In the .php file, add the following line of code:
    <?php header("Location: http://www.example.com/blog"); ?>

Remember to change the sample URL to the URL you would like the site to forward.

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


  • php redirect, php header redirect, how to, hostblast
  • 1002 Корисниците го најдоа ова како корисно
Дали Ви помогна овој одговор?

Понудени резултати

What are cron jobs?

Cron jobs are routines that execute a script on any given interval. For instance, you may have a...

What are error pages?

Error pages are the pages displayed when a user tries to access a location on your site and...

How do I configure a cron job?

Login to cPanel. Locate and click on the "Cron Jobs" icon under the "Advanced" category....

What does Network Tools do?

Network Tools enables you to query a domain and retreieve relevant information about that domain....

How to Force HTTPS Using the .htaccess

Redirect All Web Traffic To force all web traffic to use HTTPS insert the following lines of...