301 Redirect Explained
18th June 2008
|
Let’s start with the an overview of the basics. When you go to a web page, say, cnn.com , there is a lot going on behind the scenes to make that page show up in your browser. Remember, before anything can happen, a TCP/IP connection is established between your computer and the cnn.com webserver through port 80. Your browser will then start requesting “assets” to build the page. Some of these assets include HTML, CSS, Javascript and Image files, etc. They allow the browser to render the web page visible to you. The Webserver and your browser talk to each other in a protocol called HTTP (over TCP/IP). The two most common ways of communicating over HTTP are GET and POST. Without going into the gory technical details, the difference between a “GET” and a “POST” is that the “GET” method passes form data on the URL which is visible in the browser location window. In the POST method, the form data is sent along with the body of the request and is not visible in the URL. The following is an example of HTTP communication showing a GET request for the cnn.com logo which was sent to the Webserver by my browser.
Below is the response that is sent back by the Webserver to my browser.
Notice how the Webserver responded to the request from my browser with a status code of 200. This means my request has been granted and it gives me the image. My browser received the CNN logo along with other files. For each of the assets there is a request sent and a response received. You can learn more about the HTTP status codes at the official w3.org site. If you use the Internet you most likely have come across the status code 404, which means the request can’t be found. In this post I’d like to discuss the status code 301. A 301 status code returned by the Webserver my the browser that the requested URL has moved and passes a parameter containing the new location back to my server. So, included in the response is a “Location header” with the new location. My browser then makes another request for the new URL. Here is an example of a status code 301 sent by the Webserver:
Note that the browser makes 2 requests for the desired URL with the 301 redirect. The new URL can also be 301 redirected, this is called chaining and should be avoided if you want play nice with the search engine spiders. The 301 redirect is search engine friendly to some extent. This means that if a particular URL has “link juice” (it’s a popular link for some keywords) a 301 redirect should transfer the popularity to the new URL. From what I read in Search Engine Optimization with PHP (a fantastic SEO book for the technically savvy) this can take some time for the transfer to occur, so 301 redirects should be applied with caution to high ranking URL’s. PHP: JSP: Javascript: The Javascript method is not a recommended. At some point spammers were using this method and, as a result, search engines are not in favor of client side redirection using Javascript. The other methods for redirecting traffic is to use the .htaccess file. The nice thing about the .htaccess file is that you can use regular expressions when creating your redirection rules. With regular expressions you can do a mass 301 redirect if certain conditions are met. Here is a good .htaccess file tutorial. Here is an example for redirecting a single page in your .htaccess file: Redirect 301 oldpage.html to http://www.mydomain.com/newpage.html The following lines show canonical redirecting; that is when someone requests your domain without the www, they will be 301 redirected with the www. RewriteEngine On Thank you, Shimon for giving me the opportunity to post here. I hope to share additional SEO posts here with a technical twist. Related posts: |
















June 18th, 2008 at
Awesome post Ron!
As I see it, there are basically 3 reasons to use a redirect:
1) To change long messy dynamic url’s to static url’s.
2) To resolve any canonicalization issues.
3) To maintain link equity (eg: ecommerce product page/url changes).
June 18th, 2008 at
This is a very well written piece on a topic not well documented.
Keep up the good work Ron!
Ben
June 18th, 2008 at
Very nice job, for sure gonna make my roundup for the week. I agree with Ben, it is great to see more documentation on this as it is very useful at times.
June 18th, 2008 at
Great post - always trying to explain this to clients. Would love to hear your best practices for redirections on an IIS server. Hosting companies and the like loathe the idea of having to do redirections.
June 18th, 2008 at
Great Article. Here is my small contribution. If you have a URL with %20 here is the method to redirection,
say the File name starts with tips,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mydomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^tips(.*).html$ http://www.mydomain.com/ [R=301,L]
June 19th, 2008 at
Hi Ron
I recently tried to do a 301 for individual pages from a HTML to an asp page. Hosting the site in Go Daddy, It seems like Go Daddy dont support 301 redirects. Any thought?
Thank you for your nice post
Suresh
June 19th, 2008 at
Suresh - Are you using the .htaccess file to do the redirects ? Godaddy should support redirects. Can you paste what you have ?
June 20th, 2008 at
What a thorough article on something that is not covered very often - good stuff!