Ryan Jones Blog – dotCULT.com Ryan Jones Blogs About Internet Culture, Marketing, SEO, & Social Media

November 28, 2011

How To 301 Redirect A Website

Filed under: Main — Ryan Jones @ 3:37 pm


How do I 301 Redirect my website? I get asked this question more often than I should, so instead of constantly answering it I’ve decided to create a blog post I can point people to. But first, let’s start off with some background.

Why Would I Want To Redirect A Page?

There’s several valid reasons to implement a 301 redirect. Maybe you just want to move a page do a new domain. Maybe you’re combining two pages into one and need to redirect one of the URLs. Maybe you have a vanity URL that you’re using in TV or Radio because it’s smaller. If you’re taking down last year’s product, it’s a good idea to redirect the page to a newer version instead of returning a 404 not found. In fact, anytime you take down content I’d look for a place to redirect that’s helpful to the user.

So what does 301 mean anyway?

301 is the HTTP status code for a permanent redirect. The official definition of a 301 is as follows:

“The requested resource has been assigned a new permanent URI and any future references to this resource SHOULD use one of the returned URIs. Clients with link editing capabilities ought to automatically re-link references to the Request-URI to one or more of the new references returned by the server, where possible. This response is cacheable unless indicated otherwise.”

In layman’s terms it basically tells a search engine that “Hey, this page has moved to this new address. Update your records accordingly.” It also allows the search engines to properly transfer any trust or ranking signals associated with the old domain to the new one (if they so choose)

301 is the preferred method of redirection for SEO. Sadly, the default method on most IIS web servers though is a type 302. 302 returns a status of Found(Elsewhere). Realistically it should only be used when the webserver is doing it due to some hiccup, and generally never on purpose.

Wait I thought 302 meant temporary? You’re right, it did. It’s been replaced with a 307 redirect now. A 307 redirect tells search engines that “this is temporary, please re-visit the orginal URL the next time you come calling.” With a 307 or 302, no pagerank/trust/authority is passed to the resulting location. In other words, this is bad. There’s also a hardly used type 303 redirect which says “go to this other location, but use a GET request instead of a POST.” If done right, you shouldn’t ever need to use 303. (If you’re still interested in the differences, here’s a great status code pamphlet by Sebastian.

Ok, so how do I implement a 301 redirect?

There’s several ways to do a 301 redirect. .htaccess is the easiest but we’ll also cover how to do it at the page level, as well as how NOT to do it. We’ll use the basic example of redirecting the non-www version of your website to the www version. So for the examples we’ll be redirecting http://example.com to http://www.example.com

301 redirects with .htaccess

If you’re running Apache and can edit your .htaccess file this is the simplest way. Just put the following in your .htaccess file.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

301 redirects in PHP

In some cases, you can’t do it with .htaccess so you’re stuck doing it at the page level. If you need to do a 301 redirect in PHP, here’s how:

<?php
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://www.example.com/”);
?>
Note: you’ll need to make sure you don’t echo out any HTML or text before executing these functions.

301 redirects in ASP

If you’re using ASP, it looks like this:

<% Response.Status = "301 Moved Permanently" Response.AddHeader "Location", "http://www.example.com/" Response.End %>

301’s in Python

If you’re using Python you’re already geeky enough that you don’t need me to tell you, or you work at a Google. But here’s how to do it anyway:

from django import http
def view(request):
return http.HttpResponsePermanentRedirect (‘http://www.example.com/’)

301 Redirects in IIS

If you’re using IIS I pity you, but it’s still possible to do a 301 redirect. You just need to pay attention to detail and make sure you check that box that says permanent. Here’s a good guide to configuring IIS redirects. Here’s another step by step guide with screenshots.

How NOT to Redirect

No primer would be complete without telling how NOT to do it so you can avoid these SEO death traps.

Don’t Use JavaScript Redirects
JavaScript redirects aren’t guaranteed to be crawled by search engines and may not work with all users. Here’s what they look like so you can spot them.

<script type=”text/javascript”>
window.location.href=’http://www.example.com/’;
</script>
note: they could also use document.location or document.url in place of window.location.href but those are depreciated or don’t work in all browsers.

Don’t Use META refresh tags either.
Meta refresh tags are even worse than JavaScript ones, and they look like this:

<meta http-equiv=”refresh” content=”0;url=http://www.example.com/”>

And that’s all there is to it. Happy redirecting.

November 11, 2011

Over Thinking SEO: Inverse Document Frequency

Filed under: Main — Ryan Jones @ 9:26 pm

If you came to pubcon this week you probably noticed some very odd questions being asked at some sessions. My favorite question was when somebody asked @mattcutts for a better method of doing doorway pages. yeah, seriously!

My 2nd favorite question though was also Matt’s fault. At the end of one of Alan K’necht’s sessions somebody asked about inverse document frequency and how they can improve theirs to get better rankings. If you’re scratching your head right now and saying “dude, WTF?” then you’re reacting precisely how you SHOULD react.

So where did this question come from? Well, at the pubcon mixer Matt, myself, and somebody I can’t remember were bullshitting about mostly non-SEO related stuff. Anyway, we started talking about Amit Singhal’s background and how smart he is and somehow gravitated to computer science research. That’s when we got talking about the topic of Inverse Document Frequency (idf) and how big of an expert that Amit is in information retrieval.

I take some of the blame because as Matt was attempting to explain IDF in technical terms I jokingly said “basically it means that keyword stuffing is more effective where there aren’t many competing documents.” Sadly only Matt got the joke because it wasn’t just a reference to inverse document frequency, it was also a reference to how Google most likely uses inverse document frequency. Everybody else seemed confused, but giddy like they just stumpled upon some secret ranking sauce. Sorry guys, you didn’t :'(

Ok, so what does all this stuff mean? It’s quite simple but let’s start with the basics. When we say collection frequency we’re referring to how many times the given term occurs across all the documents on the web. When we say document frequency we’re referring to the number of pages on the web that contain the term. Pretty simple right? (side note: comparing your document frequency to the collection frequency is most likely one way Google detects both relevance AND keyword stuffing)

But to do that, they need the inverse document frequency. Inverse Document Frequency is simply a measure of the importance of a term. It’s calculated by dividing the total number of documents by the number of documents containing that term, and then taking the logarithm. An even more simple explanation is to say idf is computed such that rare terms have a higher idf than common terms.

So why? Basically, if there’s only a few documents that contain a term, they should get a higher relevance boost than a case where there’s multiple documents containing a term. That’s all idf really is. It’s nothing you need to worry about – unless you’re writing algorithms or dealing with document retrieval.

But I’m pretty sure Google doesn’t just use idf alone anyway. That’s way too simple of a way to return results. So let’s get more technical. Matt was getting really technical in our talk and although I don’t think he said the term, he was actually describing tf-idf, and that’s what my keyword stuffing joke was about. So, sorry if that got people thinking along the wrong lines.

So what the hell is tf-idf? Don’t let the minus sign fool you. tf-idf is actually calculated by multiplying the term frequency of a document by the inverse document frequency. This means a document with lots of a term, where there aren’t many documents containing that term will have a much higher tf-idf; hence my joke about keyword stuffing.

And that’s basically all there is to it. Sadly, inverse document frequency won’t be the new buzzword at next year’s pubcon, but that doesn’t mean it isn’t interesting. Information retrieval was a once-boring area of computer science that suddenly became the most interesting thing in the world to geeks once search engines came about. I loved that talk and and made me pine for my days in college studying computer science.

Hope that helped clear everything up. Pubcon was a blast and I’m sure many of us look forward to implementing the various theories we learned. Well, all of them except inverse document frequency of course.

November 8, 2011

Liveblogging Pubcon: SEO hot trends

Filed under: Main — Ryan Jones @ 3:28 pm

Going to take a stab at live blogging some sessions here. Moreso so that i can try out coveritlive.

Powered by WordPress