简体   繁体   English

Rails路由重定向到子域上的博客

[英]Rails Routes Redirect To Blog On Subdomain

I have moved a blog from my main domain to a sub domain and want to redirect traffic that was directed at the original blog to the same post on the subdomain using Rails 5.1 routes and wildcards. 我已经将博客从主域移动到子域,并希望使用Rails 5.1路由和通配符将定向到原始博客的流量重定向到子域上的同一帖子。

For example, my original address was https://www.dolgins.com/blog/2018/5/22/unique-hand-crafted-mosaic-jewelry-at-richard-dolgin-private-jeweler . 例如,我的原始地址是https://www.dolgins.com/blog/2018/5/22/unique-hand-crafted-mosaic-jewelry-at-richard-dolgin-private-jeweler Now, if someone enters this address, he/she would be redirected to https://blog.dolgins.com/blog/2018/5/22/unique-hand-crafted-mosaic-jewelry-at-richard-dolgin-private-jeweler . 现在,如果有人输入此地址,他/她将被重定向到https://blog.dolgins.com/blog/2018/5/22/unique-hand-crafted-mosaic-jewelry-at-richard-dolgin-private -珠宝商

Here is my current routes that pertain: 这是我当前的相关路线:

Rails.application.routes.draw do
  get 'blog/*all' => redirect(subdomain: 'blog', path: '%{all}')
  get "/blog" => redirect("https://blog.dolgins.com")
end

However, these routes redirect to http://blog.dolgins.com/2018/5/22/unique-hand-crafted-mosaic-jewelry-at-richard-dolgin-private-jeweler versus http://blog.dolgins.com /blog /2018/5/22/unique-hand-crafted-mosaic-jewelry-at-richard-dolgin-private-jeweler with the bold showing the difference. 但是,这些路由重定向到http://blog.dolgins.com/2018/5/22/unique-hand-crafted-mosaic-jewelry-at-richard-dolgin-private-jewelerhttp://blog.dolgins。 com / blog / 2018/5/22 / richard-dolgin-private-jeweler上的独特手工制作的mosaic-jewelry-at,粗体显示出区别。

Any ideas about what my routes should be? 关于我的路线应该有什么想法?

Thank you! 谢谢!

You were really close 你真的很亲近

Rails.application.routes.draw do
  get 'blog/*all' => redirect(subdomain: 'blog', path: '/blog/%{all}')
  get "/blog" => redirect("https://blog.dolgins.com")
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM