headerIMG

B2B Articles - July 23, 2010

301 Redirects In PHP

This brief article will provide code samples for creating 301 redirects in PHP.

A 301 redirect is an easy and SEO friendly way to redirect a page that has changed address. For example, if you website recently changed Content Management Systems, and the new CMS generates a different URL construct, then you may want to redirect key pages so the user does not experience an (404) error.

A 301 redirect will also help preserve the PageRank assigned to that page prior to the move. So even if you aren't concerned about visitors stumbling upon a 404 error, you may want to at least tell Google that your page has moved.

<?php
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: https://www.example.com" );
?>

Also, redirect with location header:

<?php
header('Location:https://www.example.com');
exit;
exit();
?>

Or, redirect with “Refresh” header:

<?php
header('Refresh: 0; URL=https://www.example.com');
exit;
exit();
?>

Tel 212-993-7809  

Ironpaper ®
10 East 33rd Street 
6th Floor
New York, NY 10016
Map

Ironpaper - B2B Agency

B2B Marketing and Growth Agency.

Grow your B2B business boldly. Ironpaper is a B2B marketing agency. We build growth engines for marketing and sales success. We power demand generation campaigns, ABM programs, create B2B content, strengthen sales enablement, generate qualified leads, and improve B2B marketing efforts.

Ironpaper Twitter Ironpaper Linkedin