2010-12-23 9 views

Respuesta

8

¿Quieres una expresión regular real de su ruta:

require 'sinatra' 
get %r{^/tileflood/?$}i do 
    request.url + "\n" 
end 

Prueba:

smagic:~ phrogz$ curl http://localhost:4567/tileflood 
http://localhost:4567/tileflood 

smagic:~ phrogz$ curl http://localhost:4567/tIlEflOOd 
http://localhost:4567/tIlEflOOd 

smagic:~ phrogz$ curl http://localhost:4567/TILEFLOOD/ 
http://localhost:4567/TILEFLOOD/ 

smagic:~ phrogz$ curl http://localhost:4567/TILEFLOOD/z 
<!DOCTYPE html> 
<html> 
<head> 
    <style type="text/css"> 
    body { text-align:center;font-family:helvetica,arial;font-size:22px; 
    color:#888;margin:20px} 
    #c {margin:0 auto;width:500px;text-align:left} 
    </style> 
</head> 
<body> 
    <h2>Sinatra doesn't know this ditty.</h2> 
    <img src='/__sinatra__/404.png'> 
    <div id="c"> 
    Try this: 
    <pre>get '/TILEFLOOD/z' do 
    "Hello World" 
end</pre> 
    </div> 
</body> 
</html> 

smagic:~ phrogz$ curl http://localhost:4567/tileflaad 
<!DOCTYPE html> 
<html> 
<head> 
    <style type="text/css"> 
    body { text-align:center;font-family:helvetica,arial;font-size:22px; 
    color:#888;margin:20px} 
    #c {margin:0 auto;width:500px;text-align:left} 
    </style> 
</head> 
<body> 
    <h2>Sinatra doesn't know this ditty.</h2> 
    <img src='/__sinatra__/404.png'> 
    <div id="c"> 
    Try this: 
    <pre>get '/tileflaad' do 
    "Hello World" 
end</pre> 
    </div> 
</body> 
</html> 
+0

excelente. Eso hizo el truco :) –

+1

En general, no implementaría este paso de normalización de la URL en la aplicación en sí, lo haría en nginx/apache/el servidor web que esté utilizando. –

Cuestiones relacionadas