Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
# Normalise your URLs, yo: # http://www.standardzilla.com/2007/07/09/dont-forget-your-trailing-slash/ TLD_LENGTH = 1 before_filter :remove_trailing_slashes def remove_trailing_slashes if (uri = request.request_uri).length > 1 and uri[-1,1] == '/' headers['Status'] = '301 Moved Permanently' redirect_to uri.chop return false end end before_filter :no_www def no_www if (bad_subdirs = ["ww", "www"]).any? {|s| [s]==request.subdomains(TLD_LENGTH)} headers['Status'] = '301 Moved Permanently' redirect_to :host => request.domain(TLD_LENGTH) return false end end
From the Design Piracy series on my blog: