What is a 301 redirect?
301 Redirect - this tells the SEs that your old site has "permanently moved" to your new site. Your old site will be gradually removed from the SE indexes and your new site will take its place. The advantage of using this approach is that the 301 Redirect will also transfer the link popularity gained by your old site, to the new one. The bad news is Google doesn't seem to recognize that you've simply changed domains and will subject your new domain to the aging delay as if it were a brand new site. The result is that your rankings will likely suffer, especially in more competitive markets. Follow Andy's advice on avoiding Google Sandbox.
Miroslav Chodak
All the 30x tell browsers and spiders both to 'do the same thing', but what spiders do with the results are unique to the needs of search engines. Specifically, a 301 will "suggest" to the spider that the original URL should be dropped and replaced with the subsequent one whereas the 302 "suggests" that the redirect is short lived so the original URL should be kept as the preferred means to identify the page.
Leslie Rohde
When to use a 301 redirect?
It is the URL that is important in linking, so you only need a 301 when URLs change. This includes changing url from http://yourdomain.com to http://www.yourdomain.com .
Leslie Rohde
How to implement a 301 redirect?
Implementing 301 redirect is fairly simple. The version to implement is based on your server requirements. See below for details:
Redirect Old domain to New domain (htaccess redirect)
Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
If you want to implement such redirect on your site, add the following to your .htaccess file:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.yoursite.com [NC]
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
This will redirect all non-www requests to a www version.
Miroslav Chodak
The following redirects were referenced from http://www.webconfs.com/how-to-redirect-a-webpage.php . This website was once suggested by Andy, but provided by Aaron Hu:
IIS Redirect
In internet services manager, right click on the file or folder you wish to redirect
Select the radio titled "a redirection to a URL".
Enter the redirection page
Check "The exact url entered above" and the "A permanent redirection for this resource"
Click on 'Apply'
Redirect in ColdFusion
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">
Redirect in PHP
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>
Redirect in ASP
<%@ Language=VBScript %><%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " http://www.new-url.com"
>
Redirect in ASP .NET
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>
Redirect to www (htaccess redirect)
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
If I Put an html Redirect on My Site, Will I Be De-indexed from Google?
Your old site will eventually be de-indexed from the SE?s. Your new site will not. The safest way to redirect old web pages to the new pages or old web site to the new web site and keep the same search engine rankings is to use the 301 redirect. It will also pass on the page rank from your old site to you new site.
Problem One: I have a URL that looks like this: http://www.domain.com/cars.php?toyota. I want it to look like this instead: http://www.domain.com/cars/toyota.
Solution:
RewriteEngine On
RewriteRule ^/cars/(.*) cars.php?$1 [PT]
Why This Works: Anything after /cars/ is removed, stripped and placed as a folder.
Problem Two: I have a URL that look like this: http://www.domain.com/cgi-bin/product.cgi?bottle=shampoo=oily. I want it to look like this instead: http://www.domain.com/product/shampoo/oily.
Solution Two:
RewriteEngine On
RewriteRule ^/product/([^/]*)/([^/]*)
/cgi-bin/product.cgi?bottle=$1&topic=$2 [PT]
Why This Works: It requires that the requested URL look exactly like the URL that is described in the pattern. This allows for a cleaner URL to be spidered easier.
Problem Three: I used an HTML editor before and it named all of my files .htm but I want to go to .html as a standard on my site. I need the old URLs to work as my site is heavily bookmarked, but I don't want to get hit with the duplicate content penalty.
Solution Three:
RewriteEngine On
RewriteRule (.*).htm $1.html [PT,L]
Why This Works: The "$1" passes the entire URL back and only the extension is changed. Any query string from a dynamically generated page will be passed as well.
Problem Four: I want all non-www URLs to go to their www version to protect against duplicate content issues with Google.
Solution Four:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Um, this should go without saying, but make sure you replace "domain" with your actual domain name or this isn't going to work too well for you!
If you have sub domains, you want the following code. You only want to use one instance of this code. So either use the one above, or the one below.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Why This Works: Regardless of what the user types or what another site has linked, your home page and any subpage will appear with the "www".
Problem Five: I just checked my log files and I am getting a ton of websites who are hijacking my images and referring to my site for them, thus using my bandwidth for their theft. What can I do?
Solution Five: Block the use of your image files directly on the server.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com.*$ [NC]
RewriteRule .(gif|jpg|png)$ - [F]
Why This Works: Any image file (gif, jpg, png) is rewritten to a forbidden status from any outside request, thus protecting your bandwidth. Of course, the dirty way to solve this is to change out the images to something that is a huge file to the thief's website takes forever to load. Jake Baillie made famous swapping the images to porn images, but that also got him into some trouble with some attorneys, so be careful out there.
Problem Six: I want to be able to redirect the visitors the root of the folder, not to the index.html. So instead of seeing www.domain.com/index.html they would see www.domain.com.
Solution Six:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.com [R=301,L]
Why This Works: This takes the "index.html" file and rewrites it to the root. If your main file was "index.htm" or "index.php" you would put that in there.
301 Redirects - How and When
The 301 Redirect is a "Permanent Redirect" and I never advise doing a 302 "Temporary" redirect, as you can do a meta refresh instead. The best way to understand the process is very much the same as a "change of address card" at the post office. You were living in one place and you are moving to another, so you tell the post office, "this is my old address, and this is the address I am moving to." You do the same exact thing in your.htaccess file when you want to move traffic from one location to another. Here are some examples:
Example One: I want to move page http://www.domain.com/our-long-privacy-policy-url.html to http://www.domain.com/privacy.html
Redirect 301 /our-long-privacy-policy-url.html http://www.domain.com/privacy.html
Notice that I did the "old" without the domain name as it isn't needed, just the part of the URL following the domain. The "to" portion needs the entire URL.
Example Two: We stopped carrying a certain product, so I want to send the traffic to our sister company's website instead.
Redirect 301 /discontinued-product.html http://www.sistercompany.com/current-product.html
Example Three: I want to send my PPC traffic to my site first, do a bounce and then send it to the merchant's site so they can't track that it came from a PPC campaign. First, in your PPC campaign, you send the traffic to /product-ppc-landing-page.html which has the product listed. Once the page has been reviewed by the PPC editors, you can do the redirect.
Redirect 301 /product-ppc-landing-page.html /product-redirect.html
Redirect 301 /product-redirect.html http://www.merchantsite.com/product.html?affid=5150
If you want to test to see if you did the redirect correctly, you can enter in the URL of the "old" address with this redirect checking tool.
Text Link: http://www.webconfs.com/redirect-check.php
301 Redirect - this tells the SEs that your old site has "permanently moved" to your new site. Your old site will be gradually removed from the SE indexes and your new site will take its place. The advantage of using this approach is that the 301 Redirect will also transfer the link popularity gained by your old site, to the new one. The bad news is Google doesn't seem to recognize that you've simply changed domains and will subject your new domain to the aging delay as if it were a brand new site. The result is that your rankings will likely suffer, especially in more competitive markets. Follow Andy's advice on avoiding Google Sandbox.
Miroslav Chodak
All the 30x tell browsers and spiders both to 'do the same thing', but what spiders do with the results are unique to the needs of search engines. Specifically, a 301 will "suggest" to the spider that the original URL should be dropped and replaced with the subsequent one whereas the 302 "suggests" that the redirect is short lived so the original URL should be kept as the preferred means to identify the page.
Leslie Rohde
When to use a 301 redirect?
It is the URL that is important in linking, so you only need a 301 when URLs change. This includes changing url from http://yourdomain.com to http://www.yourdomain.com .
Leslie Rohde
How to implement a 301 redirect?
Implementing 301 redirect is fairly simple. The version to implement is based on your server requirements. See below for details:
Redirect Old domain to New domain (htaccess redirect)
Create a .htaccess file with the below code, it will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
If you want to implement such redirect on your site, add the following to your .htaccess file:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www.yoursite.com [NC]
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
This will redirect all non-www requests to a www version.
Miroslav Chodak
The following redirects were referenced from http://www.webconfs.com/how-to-redirect-a-webpage.php . This website was once suggested by Andy, but provided by Aaron Hu:
IIS Redirect
In internet services manager, right click on the file or folder you wish to redirect
Select the radio titled "a redirection to a URL".
Enter the redirection page
Check "The exact url entered above" and the "A permanent redirection for this resource"
Click on 'Apply'
Redirect in ColdFusion
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value="http://www.new-url.com">
Redirect in PHP
Header( "HTTP/1.1 301 Moved Permanently" );
Header( "Location: http://www.new-url.com" );
?>
Redirect in ASP
<%@ Language=VBScript %><%
Response.Status="301 Moved Permanently" Response.AddHeader "Location", " http://www.new-url.com"
>
Redirect in ASP .NET
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}
</script>
Redirect to www (htaccess redirect)
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
Please REPLACE domain.com and www.newdomain.com with your actual domain name.
Note* This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
If I Put an html Redirect on My Site, Will I Be De-indexed from Google?
Your old site will eventually be de-indexed from the SE?s. Your new site will not. The safest way to redirect old web pages to the new pages or old web site to the new web site and keep the same search engine rankings is to use the 301 redirect. It will also pass on the page rank from your old site to you new site.
Problem One: I have a URL that looks like this: http://www.domain.com/cars.php?toyota. I want it to look like this instead: http://www.domain.com/cars/toyota.
Solution:
RewriteEngine On
RewriteRule ^/cars/(.*) cars.php?$1 [PT]
Why This Works: Anything after /cars/ is removed, stripped and placed as a folder.
Problem Two: I have a URL that look like this: http://www.domain.com/cgi-bin/product.cgi?bottle=shampoo=oily. I want it to look like this instead: http://www.domain.com/product/shampoo/oily.
Solution Two:
RewriteEngine On
RewriteRule ^/product/([^/]*)/([^/]*)
/cgi-bin/product.cgi?bottle=$1&topic=$2 [PT]
Why This Works: It requires that the requested URL look exactly like the URL that is described in the pattern. This allows for a cleaner URL to be spidered easier.
Problem Three: I used an HTML editor before and it named all of my files .htm but I want to go to .html as a standard on my site. I need the old URLs to work as my site is heavily bookmarked, but I don't want to get hit with the duplicate content penalty.
Solution Three:
RewriteEngine On
RewriteRule (.*).htm $1.html [PT,L]
Why This Works: The "$1" passes the entire URL back and only the extension is changed. Any query string from a dynamically generated page will be passed as well.
Problem Four: I want all non-www URLs to go to their www version to protect against duplicate content issues with Google.
Solution Four:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Um, this should go without saying, but make sure you replace "domain" with your actual domain name or this isn't going to work too well for you!
If you have sub domains, you want the following code. You only want to use one instance of this code. So either use the one above, or the one below.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]
Why This Works: Regardless of what the user types or what another site has linked, your home page and any subpage will appear with the "www".
Problem Five: I just checked my log files and I am getting a ton of websites who are hijacking my images and referring to my site for them, thus using my bandwidth for their theft. What can I do?
Solution Five: Block the use of your image files directly on the server.
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://domain.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com.*$ [NC]
RewriteRule .(gif|jpg|png)$ - [F]
Why This Works: Any image file (gif, jpg, png) is rewritten to a forbidden status from any outside request, thus protecting your bandwidth. Of course, the dirty way to solve this is to change out the images to something that is a huge file to the thief's website takes forever to load. Jake Baillie made famous swapping the images to porn images, but that also got him into some trouble with some attorneys, so be careful out there.
Problem Six: I want to be able to redirect the visitors the root of the folder, not to the index.html. So instead of seeing www.domain.com/index.html they would see www.domain.com.
Solution Six:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://www.domain.com [R=301,L]
Why This Works: This takes the "index.html" file and rewrites it to the root. If your main file was "index.htm" or "index.php" you would put that in there.
301 Redirects - How and When
The 301 Redirect is a "Permanent Redirect" and I never advise doing a 302 "Temporary" redirect, as you can do a meta refresh instead. The best way to understand the process is very much the same as a "change of address card" at the post office. You were living in one place and you are moving to another, so you tell the post office, "this is my old address, and this is the address I am moving to." You do the same exact thing in your.htaccess file when you want to move traffic from one location to another. Here are some examples:
Example One: I want to move page http://www.domain.com/our-long-privacy-policy-url.html to http://www.domain.com/privacy.html
Redirect 301 /our-long-privacy-policy-url.html http://www.domain.com/privacy.html
Notice that I did the "old" without the domain name as it isn't needed, just the part of the URL following the domain. The "to" portion needs the entire URL.
Example Two: We stopped carrying a certain product, so I want to send the traffic to our sister company's website instead.
Redirect 301 /discontinued-product.html http://www.sistercompany.com/current-product.html
Example Three: I want to send my PPC traffic to my site first, do a bounce and then send it to the merchant's site so they can't track that it came from a PPC campaign. First, in your PPC campaign, you send the traffic to /product-ppc-landing-page.html which has the product listed. Once the page has been reviewed by the PPC editors, you can do the redirect.
Redirect 301 /product-ppc-landing-page.html /product-redirect.html
Redirect 301 /product-redirect.html http://www.merchantsite.com/product.html?affid=5150
If you want to test to see if you did the redirect correctly, you can enter in the URL of the "old" address with this redirect checking tool.
Text Link: http://www.webconfs.com/redirect-check.php