DirectorySlash

Discussion in 'Install/Configuration' started by davidj, Jan 11, 2007.

  1. davidj

    davidj New Member

    I am running Mephisto Blog (Ruby on Rails) with LiteSpeed 2.2.6 standard. With the exception of this post, everything's been working great.

    Problem is that LiteSpeed, just like Apache, tries to help by redirecting certain URLs that don't end with a trailing slash by adding the slash back in. So in my access log, I get the following kind of pattern when posting comments:

    [11/Jan/2007:19:52:29 +0100] "POST /2007/1/8/test-blog-post/comments HTTP/1.1" 301 414

    [11/Jan/2007:19:52:29 +0100] "GET /2007/1/8/test-blog-post/comments/ HTTP/1.1" 302 127

    Even worse, this breaks Mephisto which uses this fancy way of adressing, so that users cannot post to my blog site. The problem is well documented in the Mephisto community: http://mephisto.stikipad.com/help/show/Developer+Tips

    From the above link, I have understood that in the Apache vhost section I could have set:

    <Location />
    DirectorySlash Off
    </Location>

    How can I achieve the same in LiteSpeed?

    Thanks for any help!
  2. mistwang

    mistwang LiteSpeed Staff

    Will Mephisto takes request to /2007/1/8/test-blog-post/comments/ ? If yes, I think you can try a rewrite rule which append the "/" automatically, so LSWS will not add a slash and redirect the request again.
    Just an idea, please let me know if it works or not.
  3. davidj

    davidj New Member

    Thanks for the suggestion, but I don't think it would work. I have investigated Mephisto's code some more, and the problem seems to be it caches pages to disc.

    So inside my "public" folder, there is a directory called "/2007/1/8/test-blog-post/comments" which contains the cached html pages previewing my comments. That's why LiteSpeed tries to help, by redirecting with an added "/", e.g. "/2007/1/8/test-blog-post/comments/" because it thinks I am looking for the directory.

    But the POST with a new comment should not go into the "comment" directory, but rather be forwarded to Rails which will parse the POST and make a new comment out of it. I am no expert, but this is how I understand the issue.

    In any case, I solved my issue by modifying the Mephisto code to stop caching comments to disc, i.e. I removed the troubling "comments" directory and now commenting works fine :)

    If LiteSpeed takes requests, I think something matching Apache's DirectorySlash toggle could be useful in a future release to help users turn off any unwanted directory redirects.
  4. mistwang

    mistwang LiteSpeed Staff

    It might work if Mephisto will work properly with URI "/2007/1/8/test-blog-post/comments/", since the directory slash has been added by the rewrite rule, so LSWS should not redirect the POST request, instead, the request will be forwarded to rails if there is no index.html under that directory.

    Another possible work around is to rewrite any URL like "(.*)/comments$" to "/dispatch.rb", so it will be passed directly to Rails.

Share This Page