ruby - Rails routes: redirect a wild card route -


i have website built in ruby on rails , blog built in wordpress. url main site example.com , url blog blog.example.com. because of way search engines index sites , preference directory blog opposed subdomain blog, want implement permanent redirect example.com/blog/anything redirect blog.example.com/anything regardless of how many slashes or parameters url contains. example.com/blog/a/b/c/d/e?google=true should redirect blog.example.com/a/b/c/d/e?google=true

so far following works if there 1 directory after blog:

  '/blog/:what', to: redirect('http://blog.codeundercover.com/%{what}') 

i, however, need work regardless of text comes after /blog. how do this?

your route not using wildcard route. instead, it's rails routing guide refers static segment

you'll want use wildcard globbing instead:

get '/blog/*what', to: redirect('http://blog.codeundercover.com/%{what}'), constraints: { what: /.*/ } 

Comments