PHP 301 Redirect
Permanent Page Redirection
There are several types of redirection and several means for implementing each of them. However, for
pages that have moved permanently, it’s best to use a status code 301 redirect. Using status code 301
will cause search engine robots to update their records and re‐index the page.
Here are the various status codes available for redirection:
| 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 |
| Multiple Choices |
Moved Permanently |
Found | See Other | Not Modified |
Use Proxy | Not Used | Temporary Redirect |
Read more about redirection on Wikipedia.org: http://en.wikipedia.org/wiki/URL_redirection
Redirecting an Entire Site
Say your old site is:
http://oldsite.edu/e-week/
And you wanted to move to:
http://newsite.edu/students/e-week/
- Move all of your files under oldsite.edu/e-week/ to their new location at newsite.edu/students/e-week/.
- Remove oldsite.edu/e-week/ entirely. If it is a locker, you must submit a request to eoshelp@ncsu.edu to have it formally removed.
- After the oldsite.edu/e-week/ directory has been removed, you need to create a file called "e-week.php" file in its place. Inside of e-week.php, you should place the following snippet of code:
<?PHP
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://newsite.edu/students/e-week$_SERVER[PATH_INFO]");
exit;
?>
Redirecting a Single Page
Example:
Your old page was:
http://www.my-website.com/description.php
Your new page is:
http://www.my-website.com/about.php
To redirect all visitors (including search engines bots) from description.php to the new about.php, you will need to add this snippet at the top of your description.php file. As long as description.php exists with this snippet of code, it will automatically send visitors to about.php. Heres the PHP code you will need:
<?PHP
Header("HTTP/1.1 301 Moved Permanently");
Header("Location: http://www.my-website.com/about.php");
exit;
?>