Skip Navigation
Redirect your page using PHP
Answer ID 6049   |   Last Review Date 12/12/2018

How do I redirect my <whatever page> to <whatever page>?


Customer Portal Pages


PHP is an easy and fast way to redirect your pages both permanently and temporarily.

When making a PHP redirect you need to make sure that you are putting the PHP code before the HTML tag including empty rows and spaces.  So for example:

<HTML>  <- this is wrong
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://<>");
<HTML> <- This is correct

The correct syntax is:

header ( string $string [, bool $replace = true [, int $http_response_code ]] )

So, in the int $http_response_code you could also use the 302 temporary redirect.

Another example using all the parameters on the same line would be:

<?php header("Location: https://<>", true, 301); exit; ?>

Here is a link to the redirect manual page:


If you don't use the 301 line then your viewer will see a "Moved Temporarily" redirect instead of a 301.  While this is not detrimental it is good coding practice and is more search engine friendly. (also note the " " not the ' ' ticks).


Here is a link to the redirect manual page:

The PHP home page can be found here.  It will provide free and comprehensive documentation.