I was surprised to see that RoR being such a popular framework has very few gems and documentation to make the sites more search engine friendly so I thought to write one for inBoundio as most of the results that come with Google are stale and outdated.
1. Clean Urls – RoR by default, comes with clean urls which is nice but still you certainly want /articles/marketing-tutorial instead of /articles/22, right ?
One of the easiest way to add titles in url is to override the to_param method in the model whose URLs we want to change,
Please check the excellent railscast by Ryan Bates to understand it better. Though the above method will still be having the id, if you want proper clean urls, you have to use standard gems. For slugs and permalinks, you can use friendly_id,
2. Redirection of /page/index to /page/ – You also want to redirect /page/index pages to /page. You can do this by using simple redirect in routes.rb file
There is an excellent tutorial on redirection here
3. Put Title and Description (Meta tags) on pages – RoR do have a Meta tags gem which takes care of meta tags as well as noindex, nofollow and canonical urls issues.
If Meta Tags looks too heavy, you can use metamagic gem which is more light weight with basic title, description and keywords options.
4. 301 Redirect from non www to www – On your production server, most likely you are using apache + phusion passenger, so in your /etc/apache2/sites-available/default file, you can have following code (most of it must already be there, the key is ServerAlias)
2. Optimize site for speed – You can use caching to speed up the site loading as it do play a very important part in site ranking. With RoR, you can do caching at two levels, server-side and client side, though they both are mammoth topics, let me try to cover at least the basics. This should be enough for you to get going.
Server Side Caching – You can enable server-side caching by
after this, you can add caching for any action
Client Side Caching – For client side caching, do make sure you are using CDN to deliver jQuery, bootstrap and similar libraries. Also make sure that assets are precompiled (by default, in products, assets are precompiled anyway). If it is not, you can use following settings
config.static_cache_control="public, max-age=2419200"# cache will get updated every four weeks
You can also use additional caching at http level using rack-cache gem.
3. GeoTargeting – You can use geocoder or geokit gems to use geotargeting on your content. Geokit offers multiple option for verifying geolocation liking yahoo geo API where as with geocoder, you can install all the latitudes/longitudes in a database table. After this, you can easily pull user location information by following calls.
geocoded_by:full_street_address# can also be an IP address
after_validation:geocode# auto-fetch coordinates
This can be used for redirections and showing different content to different countries.
4. Optimization for Mobiles – As per SearchEngineLand, mobile SEO will play a big role in search results on mobiles.
To optimize your site for mobiles, you can use mobile_fu gem using which you can detect user agents and can show respective stylesheets for the mobile type like iPhone, Blackberry, Nokia, android etc.