Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku + Rack-Rewrite

Still can't get this working...Rails 3.1.3, Ruby 1.9.2 on Heroku's Cedar Stack.

Trying to use https://github.com/jtrupiano/rack-rewrite to make http://domain 301 redirect to http://www.domain to no luck (app works, but no redirects happen at all).

/config/initializers/rack_rewrite.rb (MyAppName is actually the correct name, domain.com is actual domain):

MyAppName::Application.config.middleware.insert_before(Rack::Lock, Rack::Rewrite) do
    r301 %r{.*}, 'http://www.domain.com$&', :if => Proc.new {|rack_env|
    rack_env['SERVER_NAME'] != 'www.domain.com'
    }
end

Added to Gemfile:

gem 'rack-rewrite'

Did "gem install rack-rewrite", "bundle install".

No luck.

Any ideas?

UPDATE:

I have figured out PART of the problem. Since I'm just trying to serve "index.html" and it's "/style" folder, it appears that having "index.html" in "/public" overrides the rack-rewrite. If I remove "index.html", the rewrites work...but now I don't know where to put the files, or set up the routes.rb to direct to the index.html page by default...any help?

like image 233
David Avatar asked Feb 03 '26 08:02

David


1 Answers

change

rack_env['SERVER_NAME'] != 'www.domain.com'

to

rack_env['SERVER_NAME'] == 'domain.com'
like image 190
concept47 Avatar answered Feb 05 '26 21:02

concept47



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!