So you've created your site that allows you to sell all the cool desinger knitted sweaters you've made over the past few weeks and you've just stuck your site online. Five months later, no one has visited your site outside of you and grandma and she didn't even buy anything. Cheapskate. At this point you realize, to make it big, you have to get some decent ranking on the big search engines.
Now, I'm not going to even pretend like I'm MR. SEO or anything but I'm going to post a few tips that I believe can help, not harm, your page ranking and hopefully give you somewhere to start from. I'll start with three tips, if you can think of anything else, please, feel free to comment below. If you have any requests, put'em up. I can't guarantee I can fulfill them but at least there's a chance it'll spark some interest or conversation. So, here are three basic Ruby on Rails SEO tips:
1. WWW or no WWWWithout any configuration on your server or routes, your website can be accessed two ways,
http://yoursite.com and
http://www.yoursite.com. Seems harmless but the problem with this is, or so I've heard, that some search engines may consider them as two seperate sites and think that you're duplicating your content, as a means to try and trick them. They tend to frown on this so the quicker you can avoid this, the better.
UPDATE: As the anonymous posted below pointed out, the matt cutts article I had in mind when writing this, doesn't necessarily take this stance. He states that you should basically use redirects as a means to point the search engine's crawlers to the right content. I could've sworn I heard the double content idea from somebody though. Oh well, false alarm.
I believe the best and most effective way to handle this is at the web server level and for me, I'm currently using Mongrel to host my
cookmor site (no www's in that link, click it and watch it redirect) so this is how I did this redirect for Mongrel: You first need to create a mongrel.conf file to throw this code in (you'll call it when you start Mongrel, you'll see later) so create a mongrel.conf file and stick it in your railsapp/log/ folder. This goes in the mongrel.conf file:
class RedirectHost <>
def process(request, response)
if request.params["HTTP_X_FORWARDED_HOST"] == "yoursite.com"
response.start(302,true) do head, body
head["Location"] = "http://www.yoursite.com/"
head["Content-type"] = "text/html"
body.write("Please go here instead: http://noobonrails.blogspot.com/")
end
end
end
end
uri "/", :handler => RedirectHost.new, :in_front => true
Once that file is created and saved, stop mongrel. Restart it by using this statement:
mongrel_rails start -e production -p YOURDESIREDPORT -d -S log/mongrel.confBooyah. Now chances are you may not be using only mongrel to host your site, and that's ok, so to compensate,
here's how you do it with lighttpd,
here's how you do it with Apache and even
how to do it with LightSpeed. That's all I could think of.
2. Prettier URLsThis really depends on how you define pretty. If you define pretty as http://www.yourbooks.com/books/show/rails-is-fer-heroes, then you're ok. If not, you're will be getting nothing but tumbleweeds my friend. The whole thinking here is that, if the urls are easier for the search engines to read and understand, it will be easier for them to match up keywords to the proper pages on your site. Just don't try to fit too many keywords in your url, I'm sure /show/credit_reporting_for_credit_reporters_reporting_on_credit will look a little suspicious.
So, say you have a book website on which you list your books. You also have a show action in your controller that is called whenever you want to show the details of a certain book. Currently, the url on your show book page looks something like this, http://www.mybooksrox.com/books/show/422. Now that's all fine and dandy but we can do better for Google. Let's create a "named route" in your config/routes.rb file (more on routes
here). So above the
map.connect ':controller/:action/:id'
that is the defacto standard route that all routes.rb contain at the onset, stick this route:
map.book 'books/:booktitle', :controller => 'books', :action => 'show'What this is doing is telling rails to generate a URL of books/whateverbooktitleis when invoked from the books controller and show action. Where do we define booktitle? Where ever we make a call to show a recipe, like this:
<% for book in @books%>
<li>* %lt;%= link_to book.title, book_url(:booktitle => book.title) %></li><% end -%>
This does assume that you have a title column in your books table. book_url is actually calling the named route we created and we're passing the booktitle param along with it. Save your files and on whatever page you created those links on, they should now point to a url which includes the book titles.
3. Google SitemapsNow that I've typed this much, I can't really rememebr what number 3 was supposed to be... oh well. The next tip I could think of is to use Google Sitemaps for your site so that Google can easily serach and index it. There's a good, basic article
here that seems just fine. For mre information on Google sitemaps and why they're the bees kness, check out their site
here.
That's all I could think of for now. If I missed anything, please let me know. Happy coding.