Sorry I haven’t posted in A WHILE. It’s like all things with me once I get out of the habit it is a real chore to get started again. Hopefully this little post will get me back on track.
Simply put, every Sinatra route you ever write should be as such:
get '/hello/?' do "Hello" end
The important thing that you should always do is end your route with ‘/?’. This will make it so that if someone goes to www.yourdomain.com/hello or www.yourdomain.com/hello/ they will get the same result.
I can’t think of any case where you would actually want your routes to be sensitive to whether or not the trailing backslash was there, so start doing this from the beginning. I just had to go through 500 lines of routing code to add it. I’m surprised this isn’t included in every intro Sinatra tutorial, but I haven’t seen it in any of them. In case you are wondering, you don’t need to add this to the url string when you tell Sinatra to ‘redirect’ to another url. This ‘/?’ only applies to ‘get’ or ‘post’ conditions.