Help with lua redirect

Hi, i need help from any lua experts here.

I have the script provided to allow only the admin user non-GET request. That works fine, no problems.
Now i want to redirect to other server in case some users tries to access to the web viewer, orthanc viewer or osimis, but i have no idea how can I make it redirect to another orthanc instance with the study/series indexed.

I am doing like this:

function IncomingHttpRequestFilter(method, uri, ip, username, httpHeaders)
– Only allow GET requests for non-admin users

if method == ‘GET’ then
pos = string.find(uri,‘osimis-viewer’)
if pos == nil then
pos = string.find(uri,‘web-viewer’)
if pos ~=nil then
– redirect

return true
elseif username == ‘admin’ then
return true
return false

Assuming the checking uri is right, what should i write to redirect to another orthanc server? Servers IP whould be different.

Maybe you could clarify your end goal a bit? Are you wanting the user who comes to Orthanc #1 URL (using the native Orthanc explorer) to be redirected to an entirely different Orthanc #2 URL (the second Orthanc’s explorer)? Something like a proxy redirect? So we’re still talking about browsing Orthancs using the native web explorer facility?

If so, I’m not sure that’s possible in the standard Lua included with the Orthanc installation. i don’t think they anticipated wanting the Lua or Orthanc itself to act as a web proxy for a second Orthanc. That said, I suppose you might find Lua libraries which could be added to the installation in order to implement a proxy in Lua, but I suspect that would be quite the challenge.

You probably would need to back up a step and put your Orthanc behind Apache or another more sophisticated web server and run your proxy redirect from there.

Alternatively, are you wanting to pull the referenced study/series from Orthanc #2 into Orthanc #1 automatically and then let the user browse the study/series locally on Orthanc #1 using Orthanc #1’s explorer? I think it would be possible in Lua to craft the appropriate query and execute the movescu. However, the user would still need to navigate back to the explorer window to view the subject. Again, the Lua scripting as installed isn’t capable to my knowledge of performing a proxy like redirect.


I was planning to leave some orthanc servers in index-only mode and other server with the images indexed.

My goal right now is to redirect from the orthanc explorers index-only to the orthanc explorer with images. The users would need to write the “new” url to see the images.
I was also searching about lua redirect and yeah, it doesn’t look like an easy task to do. Do you think it would be possible to arrange something like that with apache? And how if that is possible? I was also thinking using in some javascript in the browser, but i don’t like it, honestly.

**the users would NOT need to write the URL. **


You can’t do a HTTP redirection using Lua scripting.

To this end, you’ll either have to implement a C/C++ plugin [1], or to create an higher-level application using the REST API of Orthanc [2,3].

If you decide to create a C/C++ plugin, here are the two functions you’ll have to use [4]:

  • OrthancPluginRegisterRestCallback()

  • OrthancPluginRedirect()

  • OrthancPluginSendUnauthorized()