Locomotive CMS ruby and Litespeed detect loop /dispatch.lsapi

Hi guys,
I'm using rails 3.2.21, locomotive CMS and LiteSpeed 4.2.21
I created Virtuals hosts and Context "Rack/Rails". In this context, I set URI is "/" and Location "[path-to]/myapp/
(Note: /myapp include public folder)
In General tab, I set that Document Root is "[path-to]/myapp/"

My site run successfully, but have a minor bug. When I edit a page in locomotive CMS and click Save button then the client'll send request as JSON use Backbone to Server, and the server'll response with JSON.
Example server code in controller:
response_to :json
def blahblah
response_with @object

And at the client, I get error 500 internal server. And I see on litespeed, I get error "detect loop redirection: /dispatch.lsapi"
I follow the guide at "https://www.litespeedtech.com/suppo...wiki:other-ext-apps:ruby-on-rails-easy-config", and I add the Rewrite tab the rules:
RewriteCond %{HTTP:X-Requested-With} !^$
RewriteRule ^/ /dispatch.lsapi [QSA,L]
But, I click Save button that I mentioned above, I get the new error "maximum number of redirect reached"

Please help me.

Thank you!
Last edited:
I changed RewriteRule ^/.*$ /dispatch.lsapi [QSA,L] as above comment but not work.

I found the problem as
response_to :json
def blahblah
response_with @object, :location => "path"

Because I set location on the headers of the response, so the system have the error. And I follow the guide as "https://www.litespeedtech.com/support/wiki/doku.php/litespeed_wiki:config:internal-redirect"

I set:
headers["X-LiteSpeed-Location"] = "path" or headers["Location"] = "path"

But it doesn't work.

Please help me.
Thank you!
Last edited:
Is that the best solution?
I want to use AJAX to get the success response and redirect to the location on javascript. Can I do it? How?

Please help me.
Thank you!


LiteSpeed Staff
What are doing is like
input url->/dispatch.lsapi->target url->/dispatch.lsapi
litespeed stops it.

You may have to use rewrite rule to rewrite the input URL directly to the target URL. then process by Rails.
avoid internal redirect in rails that need to be handled by rails again.
Simple, I only click button and use ajax to save the content. And in controller, I want to custom the Location Headers in response.
Example: header["Location"] = path
After then, in success callback of AJAX, to redirect location, I use:

url: url,
type: "application/json",
success: function(response, xhr){
window.location = xhr.getResponseHeaders("Location");

I don't understant about /dispatch.lsapi and how do I create it? and I don't know to write a rule in this case.

Please help me the detail. (step by step)
Thank you!


LiteSpeed Staff
You want a "Location" header in the response, but LiteSpeed wont allow it. I got it.

You should not use X-LiteSpeed-Location header, only use "Location" header.
The most important, you need to set status code to "30x", otherwise, server will treat it as internal redirect.
Maybe there is official way to do that, but you should be able to change status with
header["Status"] = 302
According above answer, then I changed my code to add header["Status"] = 302 but not work.
And I have the question, that is "I can only change my code and there isn't the solution so that I can config LiteSpeed". Is that right?
Last edited: