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();
?>
by Jonathan Franchell, CEO of Ironpaper - For more tips and hacks: Need to remove a new line after h1 tags? Both web designers and SEO practitioners need to employ headline tags: H1, H2, H3 in several ways to improve web page structure and tag...
The Crowded Arena of the IT Marketplace Updated December 2024 The Information Technology (IT) landscape is experiencing rapid growth and intensifying competition. IT spending is projected to reach nearly 5.1 trillion U.S. dollars in 2024, a...
Updated December, 2024 The field of digital marketing is evolving rapidly in response to new technology and changing buyer expectations. To help career-minded marketers, we’ve rounded up the top 10 skills needed to succeed in the field. These are...