Glob matching urls that aren't associated with any controller


I purchased a domain to redirect back to me rails app that has a lot of urls like "/story.php/ and I want to redirect all of them to my ‘welcome#index’

My current code is:

  get 'story.php*', to: redirect('/', status: 301)

and it’s at the top of the routes file to insure it matches first (if appropriate). I feel like I’m missing something obvious.

The fix for future reference:

get '/story.php', to: redirect('/')

and I want to give a BIG thanks to @walterdavis for being so helpful and sharing some world-class docs

Are you sure you want to wake up Rails for each of these types of things, particularly if you aren’t doing anything special with them? You might want to investigate URL rewriting in your Web server. Apache has mod_rewrite, NGINX has [something, I am sure].

It could save you a lot of cycles if you don’t have to descend all the way through the Web server, the Application server, and thence into Rails just to redirect to /.


1 Like

Thanks Walter!

Do you have any resources you’d suggest to learn how to do this? I’ve done some googling, but I the devops world is a little new to me (I’m currently hosting on heroku and believe I’m using a puma server if that makes any difference)

Oh, that’s a whole other beast, then. You don’t have a traditional Web server under your control on Heroku. I would stay with what you have, then.

On Apache, you would use these docs: mod_rewrite - Apache HTTP Server Version 2.4

On NGINX, you might start by reading the Apache docs, which are really mature, and then use this guide to translate: Convert Apache Rewrite Rules to NGINX Rewrite Rules | NGINX

Hope this helps,


1 Like

If I’m sticking with the routes file, do you know what’s wrong with the current matching I defined at the start of the thread?

Do you get an error, or does it just ignore you? Have you tried these with the server running in development mode locally, and watched the console as the request is processed?


1 Like

Have you looked through here? Rails Routing from the Outside In — Ruby on Rails Guides


1 Like