301 and 302 redirect, differences and implementation

Description:

Is there any difference between 301 and 301 redirects ?

Solution:

Practically, there is limited difference between the two. To be precise, 301 redirect signals a permanent move of the page, while 302 reffers to a temporary move.

This can influence search engine traffic, but Google has learned that because it is easier to implement a 302 redirect, developers might use it wrong, so the search engine checks for the accuracy of the redirect.

The mistakes come form the process of creting the 2 redirects, 302 being easier to develop, as follows:

Redirect 301 in PhP:

<?
Header( “HTTP/1.1 301 Moved Permanently” );
Header( “Location: http://www.newLocation.com&#8221; );
?>

Redirect 302 in PhP:

<?php
Header(“Location: http://www.temporaryLocation.com”);
exit();
?>

The redirects can also be done with .htaccess.

Redirect 301:

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^location.com [nc]
rewriterule ^(.*)$ http://www.newLocation.com/$1 [r=301,nc]

Redirect 302:

Redirect /index.html http://www.temporaryLocation

Further details about .htaccess redirect here.

About admin

Just another php developer trying to give something back to the community.
This entry was posted in Best practices, PhP, Script, Tools and tagged , , , . Bookmark the permalink.

Leave a comment