Empowering a brighter world through superior education is our commitment.

Online Calculators & Tools

PHP redirect

PHP redirect from page to URL. PHP 301 redirect.

This PHP redirection should return HTTP response status code: 301 Moved Permanently.

Search engines use the 301 response status code to transfer the page rank from the old URL to the new URL.

PHP header redirect

Replace old-page.php code with redirection code to new-page.php.

old-page.php:

<?php

header("Location: http://www.domain.com/new-page.php", true, 301);
exit();
?>

The old page must have .php file extension.

The new page can be with any extension.

PHP redirect examples

Example #1

php-redirect-test.php

<?php

header("Location: https://www.calcmagics.com/web/dev/php-redirect.html", true, 301);
exit();
?>

Example #2

php-redirect-test.htm

<?php

header("Location: https://www.calcmagics.com/web/dev/php-redirect.html", true, 301);
exit();
?>

 

PHP redirection from html file php-redirect-test.htm usually will not work because of the .html file extension, unless it is enabled in the .htaccess or httpd.conf file:

 

To enable PHP in HTML files add this code to the .htaccess or httpd.conf file:

Addtype application/x-httpd-php .htm .html

 

URL redirection