Dealing with permalinks in Rails

by Emilien Taque

When you want to improve your SEO karma, you have to play with your urls. You can use norman/friendly_id, but you can also do it yourself, it’s quite simple: just rewrite to_param method.

We can go further by creating a column for the permalink and using a hook to fill it:

On the controller side, it remains the same thanks to this Ruby behaviour:

More interesting, we can avoid duplicate content by redirecting urls with a bad permalink:

Update

Thanks to Henryk Nye, I’ve improved my :redirect_if_moved method (maybe should I rename it :redirect_if_better).

Direct quote:

Using :overwrite_params will ensure any additional parameters are unchanged.

Have SEO fun!