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

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

Environment:

Customer Portal Pages

Resolution: 

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
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: https://<www.yourSiteHere.com>");
exit;
?>
<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://<www.yourSiteHere.com>", true, 301); exit; ?>

Here is a link to the redirect manual page: http://php.net/manual/en/function.header.php

Notes:

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).

References:

Here is a link to the redirect manual page: http://php.net/manual/en/function.header.php

The PHP home page can be found here.  It will provide free and comprehensive documentation. http://php.net/

 

 

Available Languages for this Answer:

Notify Me
The page will refresh upon submission. Any pending input will be lost.