301 and 302 redirect, differences and implementation


Is there any difference between 301 and 301 redirects ?


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:

Header(“Location: http://www.temporaryLocation.com”);

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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s