Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

redirect www to top level domain

  • Loading branch information...
commit e8b1d34251d9e2c269efcefc9a6f50aff7e30c80 1 parent 01d9088
@stevenwilkin authored
Showing with 21 additions and 0 deletions.
  1. +4 −0 config.ru
  2. +17 −0 lib/no_www.rb
View
4 config.ru
@@ -1,3 +1,7 @@
+require './lib/no_www'
+
+use NoWWW
+
use Rack::Static, :urls => ['/css', '/img'], :root => '.'
run lambda { |env|
View
17 lib/no_www.rb
@@ -0,0 +1,17 @@
+class NoWWW
+
+ STARTS_WITH_WWW = /^www\./i
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ if env['HTTP_HOST'] =~ STARTS_WITH_WWW
+ [301, { 'Location' => Rack::Request.new(env).url.sub(/www\./i, '') }, ['Redirecting...']]
+ else
+ @app.call(env)
+ end
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.