Created
October 15, 2011 18:22
-
-
Save cjolly/1289924 to your computer and use it in GitHub Desktop.
SEO on Rails or Rack
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# As a general rule, I despise all things SEO with it's witchery and voodoo ways. | |
# However, these two practices are confirmed semi-non-witchcraft SEO best practice. | |
# | |
# 1. Serve your content from a consistent domain (www vs. non-www, Doesn't matter. Just be consistent) | |
# In addition this is nice for Heroku and other cloud based deployment environments that leave your app | |
# accessible from a url like http://myapp.herokuapp.com | |
# | |
# 2. Believe it or not, trailing slashes matter. The google machine interprets http://domain.com/about | |
# as a different page than domain.com/about/ | |
# (source: http://googlewebmastercentral.blogspot.com/2010/04/to-slash-or-not-to-slash.html ) | |
# https://github.com/jtrupiano/rack-rewrite | |
# Gemfile | |
gem "rack-rewrite" | |
# config/environments/production.rb | |
config.middleware.use Rack::Rewrite do | |
# SEO Rewrites | |
# - Consistent domain | |
r301 %r{.*}, "http://my-domain.com$&", | |
:if => Proc.new {|rack_env| rack_env['SERVER_NAME'] != "my-domain.com" } | |
# - Remove trailing slash | |
r301 %r{^(.+)/$}, '$1' | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Does anyone have an opinion on the best place in the middleware stack for rewrite rules? I'm thinking it could be the first middleware before
Rack::Lock