在我的公用文件夹中,我有一个文件index.html。我希望能够只使用url localhost:4567来显示页面(不显示localhost:4567/index.html)
这是我现在的红宝石剧本:
require 'sinatra'
set :public_folder, 'public'
get '/' do
redirect '/index.html'
end我已经尝试删除重定向语句,但是url仍然提供了index.html。
发布于 2017-02-09 15:35:52
您可以在这里使用send_file:
get "/" do
send_file 'public/index.html'
end您需要从工作目录(即不仅仅是public下的路径)提供文件的完整路径,而且这只在根url上工作,它一般不会为目录提供index.html页面。如果您愿意,您可能需要在Sinatra前面设置一个单独的web服务器,并对其进行适当的配置。
发布于 2017-02-09 15:33:57
重定向背后的想法正是迫使浏览器向您要重定向的位置发出新的请求。由于您不想更改url,您有两个可能的解决方案:
https://stackoverflow.com/questions/42140490
复制相似问题