Top  Previous  Next

addModRewrite allows you to create URL that do not exists in your httpd folder and translate them to existing files. This for example is very handy if you wish to create a Restful server in Girder.


For example say you'd like to accept a url in this form:




You could create a .lhtml that takes 3 cgi parameters:





 local cgi = getCGI()

 print(cgi['deviceId'] .. "<BR>")

 print(cgi['actionName'] .. "<BR>")        

 print(cgi['actionParam'] .. "<BR>")        





let's name that modrewrite.lhtml and place it in the httpd directory. In a scripting action register the rewrite. Probably a good idea to attached a GirderStarted event to this scripting action.


webserver.addModRewrite("http://([a-zA-Z0-9.]+)/devices/(\\d+)/action/([^/]+)/(.*)", "http://$1/modrewrite.lhtml?deviceId=$2&actionName=$3&actionParam=$4")


Now next time you pull up this page you should see the parameters displayed.


Note: webserver.addModRewrite should be called before the HTTP request is made.