How do I create a 301 redirect with PHP?

For old HTML files I’d typically create a 301 permanent redirect with apache by editing the .htaccess however when that isn’t an option, I use a meta redirect in the head tag like so:

<head>
    <meta http-equiv="refresh" content="3; URL=http://iamchristinabot.com">
</head>

If your old files are PHP extensions, you’re in luck, because the following method is better since it notifies search engines of a permanent redirect and moves your user to the new page. Editing the .htaccess file sometimes gives me the heebie jeebies and so this is my preferred method.

<?php
  header ('HTTP/1.1 301 Moved Permanently');
  header ('Location: http://www.newurl.com');
?>

Back to Blog

Say Hello

You can reach me by email, I'd love to hear from you.