3

I know that's it's technically possible to create a path that allows any character in it by using constraints. However, I have found that it's impossible to create a route that has a dot at the base of the path, e.g.

http://localhost:5000/.well-known/acme-challenge/

This is the route I've been using:

get ':my_root/acme-challenge/:id', to: 'pages#letsencrypt', constraints: {my_root: /.+/}

Anyone have any ideas?

picardo
  • 24,530
  • 33
  • 104
  • 151
  • I read [this](http://stackoverflow.com/questions/5222760/rails-rest-routing-dots-in-the-resource-item-id), [this](http://stackoverflow.com/questions/5369654/why-do-routes-with-a-dot-in-a-parameter-fail-to-match). Then found this [blog](http://flip.netzbeben.de/2008/07/rails-routes-and-special-characters-like-dots/). And tested like `get '/:my_root/acme-challenge/:id', to: 'settings#advanced', my_root: /.*/`, and it worked. *segment constraints* can be written without using the `constraint` keyword as per [guide](http://guides.rubyonrails.org/routing.html#segment-constraints). – Arup Rakshit Apr 01 '16 at 18:06
  • I read those posts and tried everything they outline, but can't seem to get it to work... – picardo Apr 01 '16 at 18:15
  • and you tried my solution also? Because it worked here. – Arup Rakshit Apr 01 '16 at 20:05
  • Yes, it's the first thing I tried. When you say it works for you, can you elaborate on what path you are visiting? Is it the same one as mine, i.e. `/.well-known/acme-challenge/123`? – picardo Apr 01 '16 at 21:33
  • Yes, I did like `http://localhost:3000/.well-known/acme-challenge/123` .. – Arup Rakshit Apr 02 '16 at 06:25
  • ok, thanks. I think there is something wrong with my configuration then. – picardo Apr 02 '16 at 19:46
  • @picardo I'm having the same problem - did you get it fixed? What version of Rails are you on? – Patrick O'Grady Aug 30 '16 at 16:57
  • @PatrickO'Grady I'm using 4.2.3. I haven't been able to fix it. – picardo Aug 31 '16 at 17:04

1 Answers1

0

take a look at dynamic-segments in blue you will find

By default, dynamic segments don't accept dots - this is because the dot is used as a separator for formatted routes. If you need to use a dot within a dynamic segment, add a constraint that overrides this – for example, id: /[^/]+/ allows anything except a slash.

you can try

get ':my_root/acme-challenge/:id', to: 'pages#letsencrypt', controller: /my_roo\/[^\/]+/

I hope that this helps

MZaragoza
  • 10,108
  • 9
  • 71
  • 116