问题描述
尝试使用使 301重定向到为no运气(应用程序工作,但根本没有重定向)。
/config/initializers/rack_rewrite.rb(MyAppName实际上是正确的名称,domain.com是实际的域名):
$ p $ 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'
}
结束
添加到Gemfile中:
gem'rack-rewrite'
$ c
gem install rack-rewrite,bundle install。
任何想法?
更新:
我已经找到了问题的一部分。由于我只是想为index.html服务,而且它是/ style文件夹,因此似乎在/ public中包含index.html会覆盖机架重写。如果我删除了index.html,重写工作......但现在我不知道把文件放在哪里,或者设置routes.rb默认指向index.html页面......任何帮助
解决方案更改
rack_env ['SERVER_NAME']!='www.domain.com'
到
rack_env ['SERVER_NAME'] =='domain.com'
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?
解决方案 change
rack_env['SERVER_NAME'] != 'www.domain.com'
to
rack_env['SERVER_NAME'] == 'domain.com'
这篇关于Heroku +机架重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!