php 301 redirect example

If you want to redirect your visitors to a new URL address, you need use 301 redirect.

The 301 status code means that a page has permanently moved to a new location. In today’s post, I will show you how to make a PHP redirect using the 301 “moved permanently” redirection.

Here is a example for php 301 redirect.

PHP 301 Redirect code

PHP Single Page Redirect

<?php header("HTTP/1.1 301 Moved Permanently"); header("Location:"); exit(); ?>

PHP Canonical Redirect

<?php if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') { header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.'.$_SERVER['HTTP_HOST'] .$_SERVER['REQUEST_URI']); } ?>

More read: 301 redirect htaccess

Enjoy redirecting PHP pages.

Related Posts

How to choose a best domain name