Locomotive CMS ruby and Litespeed detect loop /dispatch.lsapi

Discussion in 'Ruby/Rails' started by cpvinh, Mar 5, 2015.

  1. cpvinh

    cpvinh Member

    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: Mar 5, 2015
  2. NiteWave

    NiteWave Administrator

    how about
    RewriteRule ^/ /dispatch.lsapi [QSA,L]
    RewriteRule ^/.*$ /dispatch.lsapi [QSA,L]

  3. cpvinh

    cpvinh Member

    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: Mar 5, 2015
  4. NiteWave

    NiteWave Administrator

    maybe need add
    redirect_to( "path")
    somewhere ? (after headers["Location"] = "path")
  5. cpvinh

    cpvinh Member

    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!
  6. mistwang

    mistwang 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.
  7. cpvinh

    cpvinh Member

    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!
  8. mistwang

    mistwang 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
  9. cpvinh

    cpvinh Member

    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: Mar 6, 2015
  10. mistwang

    mistwang LiteSpeed Staff

    Looks like the status code does not change to 302, try
    That's right, you need to change your code to set status code to 30x.

Share This Page