What’s the difference between 301 and 302 redirect?

This article was written by in January 11, 2015, & may not be posted on other sites!
Original source url for this article: What’s the difference between 301 and 302 redirect?

What’s the difference between 301 and 302 redirect
If you are moving a website permanently or temporary you could use 301 or 302 redirect to tell search engines like Google what’s going on. But what is the difference between 301 and 302 redirect? And how can you keep your SEO, rankings, visitor rate and url paths intact when moving a website? This is how to:

The difference between 301 and 302 redirect

 

The difference between 301 and 302 redirect?

301 redirect means “permanently moved”
Use 301 redirect if your website is moving permanently from point A to B or if the URL structure has changed. A 301 redirect will have search engines like Google also redirecting most of the worked in ranking, SEO, earnings & visitor rates. Only use 301 if your website is moving truly permanently – as in forever.

302 redirect means “temporary moved”
Use 302 redirect if your website is only moving temporary to keep the SEO and ranking on your old website. With a 302 redirect you are telling the search engines that your old content is offline only temporary and they will keep the value of that page intact.

 

How to 301 or 302 redirect and keeping all url paths the same

Use this redirect method if you moved a website from www.old-domain.com to www.new-domain.com and all of the subpages and content have identical url paths on both websites. This means that the visitor will be sent from www.old-domain.com/subpage to www.new-domain.com/subpage. Add this code in your .htaccess on your old domain to forward users and keeping url paths the same when using 301 or 302 redirect:
301 .htaccess
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.new-domain.com$1 [R=301,L]

301 redirect using PHP
<?php
if ($_SERVER['HTTP_HOST'] != 'www.new-domain.com') {
header('HTTP/1.1 301 Moved Permanently');
header("Location: http://www.new-domain.com".$_SERVER['REQUEST_URI']);
die();
}
?>

302 .htaccess 
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.new-domain.com$1 [R=302,L]

302 using PHP
<?php
if ($_SERVER['HTTP_HOST'] != 'www.new-domain.com') {
header('HTTP/1.1 302 Moved Temporary');
header("Location: http://www.new-domain.com".$_SERVER['REQUEST_URI']);
die();
}
?>

 

How to 301 or 302 redirect a single url

To 301 redirect a singel url using 301 redirect, add this code to your .htaccess on your old domain to forward visitors to the new page.
301 – Redirect 301 /old-page.html http://www.new-website.com/new-page.html
302 – Redirect 302 /old-page.html http://www.new-website.com/new-page.html

If the above is not working for some reason, try this code:
RewriteRule ^old-page.html$ http://www.new-website.com/new-page.html [R=301,L]

How to 301 or 302 redirect a single url using PHP
Put this php code on the page you wish to forward and add your new location.
301
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://new-website.com/");
die();
?>
302
<?php
header("HTTP/1.1 302 Moved Temporary");
header("Location: http://new-website.com/");
die();
?>

 

301 or 302 redirect everything from old page to one single page

This 301 or 302 redirect code will send the visitor from any page on the old website to the index page of the new website. Put this code inside the .htaccess on your old domain.
301Redirect 301 / http://www.new-website.com/
302Redirect 302 / http://www.new-website.com/

 

Changing a specific path when url don’t quite match, using 301 or 302 redirect

If the path doesn’t quite match on your old website vs your new website, use this code to change any given path:
301RedirectMatch 301 ^/some-old-path/(.+)$ http://www.new-website.com/new-path/$1
302RedirectMatch 302 ^/some-old-path/(.+)$ http://www.new-website.com/new-path/$1

 

Spread the word

Facebooktwittergoogle_pluslinkedinmail

Leave a Reply

Your email address will not be published. Required fields are marked *