简体   繁体   中英

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.

For example, my original address was 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 .

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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