return to rop

Breadcrumb Navigation:

Home > Web Services > Web Articles > PHP Redirect

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/

  1. Move all of your files under oldsite.edu/e-week/ to their new location at newsite.edu/students/e-week/.
  2. 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.
  3. 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;
?>

return to rop
Information Technology and Engineering Computer Services North Carolina State University
Raleigh, NC 27695-7901   (919) 515-2458
return to rop