ruby-on-rails - 获取 url :local/ads.txt 以重定向到 public/ads.txt 文件
问题描述
我有一个ads.txt
存储在public/ads.txt
其中的文件,可以通过mywebsiteurl.com/ads.txt
但我也希望使用本地参数访问此文件,例如mywebsiteurl.com/en/ads.txt
路线.rb
Rails.application.routes.draw do
get 'ads.txt', to: redirect("/ads.txt")
scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
resources :offers
...
end
end
当本地参数存在时,我该如何访问 ads.txt?(我试图将 get 'ads.txt' 路由放在我的 :locale 范围内,但它不起作用。有什么想法吗?
解决方案
您实际上并不需要get 'asd.txt'
路由重定向,网络服务器(nginx、apache 等)应该从 /public 提供文件,而无需接触您的 rails 应用程序。
对于您的实际问题,您应该能够做到这一点:
scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
get 'asd.txt', redirect_to('/asd.txt') # this should match ":local/asd.txt" request
resources :offers
...
end
推荐阅读
- compression - 霍夫曼编码可以压缩哪些类型的文件?
- node.js - 将 Node.JS express API 应用部署到 Azure 应用服务
- snowflake-cloud-data-platform - 雪花卸载喙文件成太多小文件
- reactjs - 应用多个动态过滤器
- r - 为什么我在 lapply 函数中的“对比度”中出现错误?
- javascript - 如何在 Ngrx 9.x 中设置状态值?
- python - 如何在 Spacy 依赖解析中获取单词索引?
- jquery - 使用特殊的 jquery 代码点击执行某些操作
- node.js - 语义释放 - 错误:找不到模块“../输出”
- port - Nmap扫描结果:过滤所有1000个端口(HTB机器)