# Removing the www before a domain with Rails3?

**URL:** <https://www.ruby-forum.com/t/removing-the-www-before-a-domain-with-rails3/193928>\
**Category:** Rails\
**Created:** [August 26, 2010, 5:38pm UTC](https://www.ruby-forum.com/t/removing-the-www-before-a-domain-with-rails3/193928 "2010-08-26T17:38:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![WSzP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f14d63/32.png) [@WSzP](https://www.ruby-forum.com/u/WSzP)\
**Post date:** [August 26, 2010, 5:38pm UTC](https://www.ruby-forum.com/t/removing-the-www-before-a-domain-with-rails3/193928/1 "2010-08-26T17:38:13Z")

</div>

Hello,  
In Rails2 I used a middleware to redirect www.mydomain.tld to  
mydomain.tld.  
Something like this: [http://pastie.org/1118140](http://pastie.org/1118140)  
It is in Libs, with filename “no\_www.rb”.  
I tryed to add as the first line of environment.rb as suggested in  
here: [Rails on Rack — Ruby on Rails Guides](http://edgeguides.rubyonrails.org/rails_on_rack.html)

When it failed l put it in application,rb, the first line after class  
Application \< Rails::Application in application.rb is:  
config.middleware.use “NoWWW”  
But when I try to run the app I get: C:/Ruby/lib/ruby/gems/1.9.1/gems/  
activesupport-3.0.0.rc2/lib/active\_support/inflector/methods.rb:124:in  
`block in constantize’: uninitialized constant NoWWW (NameError)

Any idea how to use it? Unfortunately I can’t use mod\_rewrite, since I  
plan to put the app. on Heroku.

---

<div class="post-metadata">

**Author:** ![WSzP](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/f14d63/32.png) [@WSzP](https://www.ruby-forum.com/u/WSzP)\
**Post date:** [August 26, 2010, 6:13pm UTC](https://www.ruby-forum.com/t/removing-the-www-before-a-domain-with-rails3/193928/2 "2010-08-26T18:13:20Z")

</div>

I have found the solution.  
The config.middleware.use should be put into application.rb, and the /  
lib is no longer loaded automatically so you need to load it, like  
this:

class Application \< Rails::Application  
config.autoload\_paths += %W(#{Rails.root}/lib)  
config.middleware.use “NoWWW”  
…

Hope this helps someone.
