我的网站是在这里 。
它曾经是一个Django的博客。 不过,我不再对其进行更新,所以我只是想使它成为一个静态的HTML网站。 我wget'ed它,它使用Ruby架移动到的Heroku。
但是每一个URL解析为主页。 这是因为我的config.ru文件:
use Rack::Static,
:urls => ["/media/images", "/media/js", "/media/css"],
:root => "public"
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
问:有没有一种方法来映射多个URL? 例如foo.com/about
映射到public/about/index.html
, foo.com/posts/2012/oct/21/blog-post
映射到public/posts/2012/oct/21/blog-post/index.html
在这一点上,我甚至会被罚款打字每一个手工制作。
谢谢你的帮助。
现在我找到了最好的答案是:
use Rack::Static,
:urls => ["/media/images", "/media/js", "/media/css"],
:root => "public"
map "/" do
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/index.html', File::RDONLY)
]
}
end
map "/portfolio" do
run lambda { |env|
[
200,
{
'Content-Type' => 'text/html',
'Cache-Control' => 'public, max-age=86400'
},
File.open('public/portfolio/index.html', File::RDONLY)
]
}
end
和每一个URL映射到其相应的文件。 乏味,但作品。 又见回答关于URL变量这个问题 。 无法得到它为我的工作,虽然。
为什么你需要run
的语句? 也许这对你的作品:
use Rack::Static,
:urls => ["/media/images", "/media/js", "/media/css"],
:root => "public",
:index => "index.html",
:header_rules => [
[:all, {'Cache-Control' => 'public, max-age=86400'}]
]
run lambda{ |env| [ 404, { 'Content-Type' => 'text/html' }, ['404 - page not found'] ] }